
14 Apr
2006
14 Apr
'06
11:44 a.m.
On 14/04/06, Dave Menendez
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.