[Haskell-cafe] Wikipedia on first-class object
jonathanccast at fastmail.fm
Thu Dec 27 10:35:54 EST 2007
On 27 Dec 2007, at 4:57 AM, Cristian Baboi wrote:
> On Thu, 27 Dec 2007 12:40:22 +0200, Yitzchak Gale <gale at sefer.org>
>> I wrote:
>>>> On the other hand, functions are members of types
>>>> that are just like any other Haskell type. They are
>>>> first-class in that sense.
>> Cristian Baboi wrote:
>>> I guess that would apply to any typed language.
>> Perhaps. But for many typed languages, it is not
>> practical to use. There may be problems with type
>> safety, or it may create a program that would
>> be considered hard to understand.
>> For example, in Haskell, you create a list of functions just
>> the same way you create a list of anything else.
>> You can then map a value across the functions, or
>> fold the functions together with the composition
>> operator, etc. These are normal, clear idioms
>> in Haskell that could easily appear in any simple
>> program. That is also true for some other functional
>> programming languages, but it is rare for
>> imperative ones.
>> Sometimes there is a particular style within a language
>> that works something like this. For example,
>> you can use C++ with STL that way in a certain sense.
>> Anyway, that is what I think it means when we say that
>> functions are first-class in Haskell.
> Ah! You must have been thinking that function in Haskell are
> members of DATA types.
> Or, to put it another way, Haskell make no distinction between data
> types and function types.
>>>> Like any type, only certain operations make
>>>> sense on functions. Strings can be compared to each
>>>> other for equality and written to a disk, and you
>>>> can take the logarithm of a float, but none of those
>>>> operations make sense for functions. In particular,
>>>> two functions are equal only if they produce
>>>> the same value for every input, and in general it is
>>>> impossible for a computer to check that.
>>> Yes, but one can store the result of an operation to disk except
>>> in the
>>> particular case the result happen to be a function.
>> No, you can only store the result of an operation to
>> disk in the particular case that the result type represents
>> a list of bytes. Otherwise, you have to serialize it first.
>> Happily, Haskell has some cool tools for easily creating
>> methods. And there are a number methods that are already
>> provided in the libraries for many types and for many
>> uses - the Read and Show classes are just one example.
>> But it is not clear at all how you could define a general
>> serialization method for functions. If you can come up
>> with one, please post it to Hackage. :)
> Isn't that confusing levels of abstractions ?
> Of course functions are bytes, 'cause they are already stored as
> bytes in RAM.
Only on Von Neuman machines. Haskell implementations are not
required to run on Von Neuman machines. That's why the language is
called functional. (Imperative languages, by contrast, are just
abstractions of the underlying Von Neuman architecture, which is
probably the source of your confusion).
More information about the Haskell-Cafe