All Monads are Functors

Taral taralx at gmail.com
Tue Aug 15 17:25:03 EDT 2006


On 8/15/06, Bulat Ziganshin <bulat.ziganshin at gmail.com> wrote:
> in this case we lose "class Functor a => Monad a" base class
> declaration. so what will be the meaning of this:

I don't see why that is the case.

class Functor m => Monad m where
    return :: a -> m a
    (>>=) :: m a -> (a -> m b) -> m b
    instance Functor m where
        fmap f = (>>= return . f)

What's wrong with this? All Monads are Functors. If you don't provide
a Functor, it gets defined for you. The problem is working out whether
to use the default Functor or an external Functor.

-- 
Taral <taralx at gmail.com>
"You can't prove anything."
    -- Gödel's Incompetence Theorem


More information about the Haskell-prime mailing list