Defaults for superclass methods
cgibbard at gmail.com
Fri Apr 14 11:44:26 EDT 2006
On 14/04/06, Dave Menendez <dave at zednenem.com> wrote:
> The tricky part is dealing with multiple subclasses.
> For example,
> class Functor f where
> fmap :: (a -> b) -> f a -> f b
> class Functor f => Monad f where
> fmap = liftM
> class Functor f => Comonad f where
> fmap = liftW
> newtype Id a = Id a
> instance Functor Id
> instance Monad Id
> instance Comonad Id
> Which default gets used for fmap?
The simple solution is to make it an error, and force the programmer
to define an instance of Functor as soon as that happens. Most of the
problems seem to happen in mostly-linear hierarchies anyway.
More information about the Haskell-prime