[Haskell-cafe] The Trivial Monad

Dan Piponi dpiponi at gmail.com
Fri May 4 12:47:49 EDT 2007


Hi Adrian,

> They take a function f and something and return what f does to that. I
> don't see why they should return a function.

Consider a function, f, that takes two arguments, one of type A, and
one of type B, and returns something of type C. In conventional
mathematical notation this would be written as f : A x B -> C.

Think about what this function does from a practical point of view. It
waits to be handed an object of type A. It then waits for an object of
type B. And now it can return an object of type C.

But suppose we hand f an object of type A, but not another of type B.
What do we get? Well we basically have something that's still waiting
for an object of type B, and when it gets that it'll return an object
of type C. Something that's waiting for a B in order to give you a C
is of type B->C. So after you've given f an A, you get back a B->C. So
f can be thought of as being of type A->(B->C).

So there are two ways of thinking of f. (1) A function that takes an A
and a B and gives you a C. Or (2) a function that takes an A and gives
you back a function mapping a B to a C. Haskell blurs the distinction
between these things and the transition from view (1) to view (2) is
called 'currying'.

Internally, the Haskell parser automatically converts A->B->C to
A->(B->C) so you can view the former as simply being shorthand for the
latter. (In CS-speak '->' is considered to be right associative but
that's just another way of saying the same thing.)
--
Dan


More information about the Haskell-Cafe mailing list