All Monads are Functors

Ashley Yakeley ashley at semantic.org
Fri Aug 25 22:09:11 EDT 2006


Jon Fairbairn wrote:

 > There has been discussion in the past about whether Monad
 > should be defined as
 >
 >> class Functor m => Monad m where ...

It's more complicated now that we have Ross Patterson's "Applicative".

http://haskell.org/ghc/dist/current/docs/libraries/base/Control-Applicative.html

The correct decl I think is this:

   class Applicative m => Monad m where
     -- remove "return"
     ...

and changing the names of the Applicative functions:

   class Functor f => Applicative f where
     return :: a -> f a
     ap :: f (a -> b) -> f a -> f b

This would mean moving Applicative into the Prelude.

I think "joining up the classes" is a good idea, and there may be other 
cases too. "Alternative" and "MonadPlus"?

-- 
Ashley Yakeley



More information about the Haskell-prime mailing list