[Haskell-cafe] Wikipedia on first-class object
Yitzchak Gale
gale at sefer.org
Thu Dec 27 04:10:21 EST 2007
Cristian Baboi wrote:
> http://en.wikipedia.org/wiki/First-class_object
> I'll guess that 5,9,12 does not apply to Haskell functions.
I think there is a basic semantic difference between
what the author of that article meant by the word
"function" and what we mean by that word when
we are talking about Haskell.
In the article, "function" means a concrete
data object that specifies how to compute something.
In Haskell, a function is closer to the mathematical
idea of a function. Functions specify relationships between
elements of certain types, and then the compiler
uses them to create code to do your computation.
But there is no obligation for a compiler to create
any concrete data structure that corresponds to
a function. Often it does in practice, but not
always.
On the other hand, functions are members of types
that are just like any other Haskell type. They are
first-class in that sense.
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.
-Yitz
More information about the Haskell-Cafe
mailing list