[Haskell] The FunctorM library

Ross Paterson ross at soi.city.ac.uk
Thu Mar 24 06:25:47 EST 2005


On Thu, Mar 24, 2005 at 08:40:14AM -0000, Simon Peyton-Jones wrote:
> [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...
> 
> It seems overkill to have a whole new language feature to deal with one
> library issue.  It would take a bit of implementing too, and it's not
> clear to me what the specification is.  For example, what if Functor T
> *is* defined explicitly, but in a later module?

It's not just here -- this would make lots of fairly fine-grained class
hierarchies a lot less painful.  But I agree that there's a cross-module
problem.  It may be necessary to require that instances of classes
linked in this way be defined in the same module, but that wouldn't be
backwards compatible either.


More information about the Haskell mailing list