All Monads are Functors

Jon Fairbairn jon.fairbairn at cl.cam.ac.uk
Sun Aug 13 12:11:06 EDT 2006


I find myself dismayed that the mathematical relationship
between Monads and Functors isn't available in Haskell98; if
I use fmap in a Monad m=>... typed function, I get an extra
Functor m required in the context, but not only are all
mathematical monads functors, any instance of Monad has fmap
in the form (>>= return . f), so it's annoying.

There has been discussion in the past about whether Monad
should be defined as 

> class Functor m => Monad m where ...

(or some other means of making all Monads instances of
Functor) I think the general consensus on the libraries
mailing list in this thread

http://thread.gmane.org/gmane.comp.lang.haskell.libraries/2815/focus=2815

which refers to this:

http://www.cs.chalmers.se/~rjmh/Haskell/Messages/Display.cgi?id=444

was that it would be a good thing, but it breaks Haskell98
programmes. Surely Haskell' can get this right?

On haskell prime I can find 

http://thread.gmane.org/gmane.comp.lang.haskell.prime/1328/focus=1427

which agrees with me, but I don't see a definite decision
either there or in the Trac.

I'd favour the above method as most conservative in terms of
the language, but I'm not too fussed how it happens.

  Jón


-- 
Jón Fairbairn                              Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-prime mailing list