[Haskell] The FunctorM library

Cale Gibbard cgibbard at gmail.com
Wed Mar 23 23:29:51 EST 2005


On Wed, 23 Mar 2005 19:14:41 -0800, Thomas Hallgren
<hallgren at cse.ogi.edu> wrote:
> Iavor Diatchki wrote:
>
> >Just to avoid confusion I think the suggestions were:
> >class Functor f => Monad f where ...
> >class Functor f => FunctorM f where ...
> >
> >I know the first one differs from the Haskell report, but perhaps this
> >is a flaw in the library design that should be fixed.
> >
> Yes, I think this should be fixed, and perhaps it could be done in a
> backward compatible way? If classes were allowed to declare default
> methods for superclasses, then you could have
>
>     class Functor f where fmap :: ...
>     class Functor m => Monad m where
>        ...the usual stuff...
>        fmap = liftM
>
> Then declaring
>
>     instance Monad T where ...
>
> for some T, would implicitly introduce an instance Functor T, if it is
> not defined explicitly...
>
> --
> Thomas H
>

I agree, and think that's a great idea for solving that problem.
Does anyone see any possible difficulties with it?
I think that perhaps specifying the entire instance might make more sense, eg:

class Functor m => Monad m where
    {- ... usual stuff ... -}
    instance Functor m where
        fmap = liftM

Having such a thing seems quite useful. As long as it doesn't break
the world, I'd personally like to have this feature.

One issue might be which default instance gets chosen when two classes
both provide default instances for a given class. Perhaps in this
case, we can just force the user to provide an instance, or produce a
compile-time warning and select one automatically in some canonical
fashion.

What do the Simons think?

 - Cale


More information about the Haskell mailing list