[Haskell-cafe] Comments from OCaml Hacker Brian Hurt

Eugene Kirpichov ekirpichov at gmail.com
Sat Jan 17 06:34:25 EST 2009

2009/1/17 Andrew Coppin <andrewcoppin at btinternet.com>:
> Cory Knapp wrote:
>> Actually, that was part of my point: When I mention Haskell to people, and
>> when I start describing it, they're generally frightened enough by the focus
>> on pure code and lazy evaluation-- add to this the inherently abstract
>> nature, and we can name typeclasses "cuddlyKitten", and the language is
>> still going to scare J. R. Programmer. By "inherently mathematical nature",
>> I didn't mean names like "monoid" and "functor", I meant *concepts* like
>> monoid and functor. Not that either of them are actually terribly difficult;
>> the problem is that they are terribly abstract. That draws a lot of people
>> (especially mathematicians), but most people who aren' drawn by that are
>> hugely put off-- whatever the name is. So, I guess my point is that the name
>> is irrelevant: the language is going to intimidate a lot of people who are
>> intimidated by the vocabulary.
> Oh, I don't know. I have no idea what the mathematical definition of
> "functor" is, but as far as I can tell, the Haskell typeclass merely allows
> you to apply a function simultaneously to all elements of a collection.
> That's pretty concrete - and trivial. If it weren't for the seemingly
> cryptic name, nobody would think twice about it. (Not sure exactly what
> you'd call it though...)

No, a functor is a more wide notion than that, it has nothing to do
with collections.
An explanation more close to truth would be "A structure is a functor
if it provides a way to convert a structure over X to a structure over
Y, given a function X -> Y, while preserving the underlying
'structure'", where preserving structure means being compatible with
composition and identity.

Collections are one particular case.

Another case is just functions with fixed domain A: given a
"structure" of type [A->]X and a function of type X -> Y, you may
build an [A->]Y.

Yet another case are monads (actually, the example above is the Reader
monad): given a monadic computation of type 'm a' and a function a ->
b, you may get a computation of type m b:

instance (Monad m) => Functor m where
  fmap f ma = do a <- ma; return (f a)

There are extremely many other examples of functors; they are as
ubiquitous as monoids and monads :)

Eugene Kirpichov

More information about the Haskell-Cafe mailing list