[Haskell-cafe] IO is not a monad

Yitzchak Gale gale at sefer.org
Tue Jan 23 17:33:09 EST 2007


Hi Brian,

Brian Hulley wrote:
> I thought it was:
>     return x >>= f = f x
> ...I think the problem you're encountering is just
> that the above law doesn't imply:
>     (>>= f) . return = f

Sorry, I was not clear.

For the purposes of this thread, I am using the
word "monad" in the category-theoretic sense.

The monad axioms are stated in terms of morphisms
and composition in the category. If we then define -
in the category - for each morphism f, a morphism

(>>= f) = join . fmap f

then we can derive the identities

(>>= return) = id
(>>= f) . return = f
(>>= g) . (>>= f) = (>>= (>>= g) . f)

directly from the monad axioms. Assume, for now,
that morphisms in the category will exactly correspond
to functions in Haskell. Then the above identities will be the
conditions for a monad in Haskell.

The conditions for a monad in Haskell are usually
stated in the non-points-free form, presumably for
clarity. But as you pointed out, that is _not_ equivalent
to the above when we are being careful about strictness.

My challenge is:

1. Find a way to model strictness/laziness properties
of Haskell functions in a category in a way that is
reasonably rich.

2. Map monads in that category to Haskell, and
see what we get.

3. Compare that to the traditional concept of
a monad in Haskell.

Is this possible? Any more ideas how to proceed?

I told you this was a troll. :)

Thanks,
Yitz


More information about the Haskell-Cafe mailing list