[Haskell-cafe] IO is not a monad

Yitzchak Gale gale at sefer.org
Wed Feb 7 07:39:20 EST 2007


Just for the record, I think this completes the
requirements of my challenge. Please comment!
Is this correct?
Thanks.

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

We use HaskL, the category of Haskell types, Haskell
functions, and strict composition:

f .! g = f `seq` g `seq` (f . g)

Let undef = \_ -> undefined. A function f is strict iff
f .! undef = undef, lazy iff f .! undef /= undef, and
convergent iff f .! g /= undef for all g /= undef.

We consider only functors for which fmap is a
morphism.
A functor preserves strictness iff fmap is strict.
A functor preserves laziness iff fmap is convergent.

Note that with these definitions, undefined is lazy.

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

Assume that return /= undef, and that >>= is convergent
in its second argument.

The monad laws are:

1. (>>= return) = id
2. (>>= f) . return = f
3. (>>= g) . (>>= f) = (>>= (>>= g) . f)
4. >>= is strict in its second argument.

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

As long as we are careful to use the points-free
version, the laws are the same as the traditional
monad laws. In particular, we can use the usual
composition for these laws. But we must add the
strictness law.


More information about the Haskell-Cafe mailing list