The FunctorM library

Ross Paterson ross at
Tue Mar 29 05:22:33 EST 2005

On Thu, Mar 24, 2005 at 12:39:40PM +0100, Benjamin Franksen wrote:
> On Thursday 24 March 2005 04:14, Thomas Hallgren wrote:
> > 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...
> Robert Will has written a fully specified proposal for this. He calls it 
> "delayed method definition", see 
>, sections 4.3.1 and 
> 4.3.2.

I'd prefer something more modest: classes could contain default methods
for their superclasses, but only for a superclass with exactly the
same arguments, as in

	class Eq a => Ord a
	class Functor m => Monad m

so there'd be no need for a special device to specify which class the
default method is for.  This would lose things like the ability to specify
general equality on Collections in the class

	class (Eq a, Eq (coll a)) => Collection coll a

but I think that's stretching subtyping a bit.

It would also be simpler to keep the H98 rule for instances, namely that
an instance of class C can contain only definitions of methods of class C.

More information about the Libraries mailing list