[Haskell-cafe] Wikipedia on first-class object

Cristian Baboi cristi at ot.onrc.ro
Thu Dec 27 05:57:15 EST 2007


On Thu, 27 Dec 2007 12:40:22 +0200, Yitzchak Gale <gale at sefer.org> wrote:

> 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 serialization
> 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.

>> 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 ()
>
> The result type of this function is IO (), which means an
> IO action. In this case, the semantics of the action are
> that, when performed, it writes the bytes into a file.

And this is a property of the type String ?
The function hPutStr appears in the definition of the type String ?



________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Servers.
  part000.txt - is OK
http://www.eset.com


More information about the Haskell-Cafe mailing list