[Haskell-cafe] Wikipedia on first-class object
gale at sefer.org
Thu Dec 27 07:37:51 EST 2007
Cristian Baboi wrote:
> 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...
>>> 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...
>> But it is not clear at all how you could define a general
>> serialization method for functions.
> Isn't that confusing levels of abstractions ?
> Of course functions are bytes, 'cause they are already stored as bytes in
That is just the point. A function in Haskell is an abstraction,
not bytes in RAM.
The compiler might implement the same function in several places,
with different bytes in each place. Or it might decide to combine it
into other functions, and not store any bytes in RAM at all for this
The function itself represents a way of doing a calculation. It is not an
object that can do the calculation.
>>> I'm not sure that in Haskell one can say that storing a value
>>> of some type to disk is an operation defined on that type.
>> It is. For example:
>> hPutStr :: Handle -> String -> IO ()
> And this is a property of the type String ?
> The function hPutStr appears in the definition of the type String ?
Ah, you are thinking of "operation on a type" in the OOP sense.
Sorry, I wasn't clear. When I said "only certain operations make
sense" on each type, I just meant that there are only certain
things you can do with the type. In Haskell, the things you can
do with a type are the functions you can define that mention that
type in their signature.
More information about the Haskell-Cafe