All Monads are Functors

Lennart Augustsson lennart at augustsson.net
Sun Aug 13 22:02:25 EDT 2006


If I remember right, Functor was a superclass of Monad in Haskell  
early on, but it was taken away.  I think this was the wrong  
decision, but I seem to remember that the rationale was that it would  
be too onerous to require programmers to write a Functor instance  
every time they want a Monad instance.  Bah!

	-- Lennart

On Aug 13, 2006, at 21:39 , Donald Bruce Stewart wrote:

> jon.fairbairn:
>> 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.
>
> For interest. Here's the defn in the Gofer prelude from 1994:
>
>     class Functor f where
>         map :: (a -> b) -> (f a -> f b)
>
>     class Functor m => Monad m where
>         result    :: a -> m a
>         join      :: m (m a) -> m a
>         bind      :: m a -> (a -> m b) -> m b
>
>         join x     = bind x id
>         x `bind` f = join (map f x)
>
>     class Monad m => Monad0 m where
>         zero   :: m a
>
> http://www.cse.unsw.edu.au/~dons/data/cc.prelude
>
> -- Don
> _______________________________________________
> Haskell-prime mailing list
> Haskell-prime at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-prime



More information about the Haskell-prime mailing list