[Haskell-cafe] Redefining superclass default methods in a subclass

Roberto Zunino zunino at di.unipi.it
Thu Jan 4 17:44:03 EST 2007

Brian Hulley wrote:
> Hi,
> Looking at some of the ideas in 
> http://www.haskell.org/haskellwiki/The_Other_Prelude , it struck me that 
> the class system at the moment suffers from the problem that as 
> hierarchies get deeper, the programmer is burdened more and more by the 
> need to cut-and-paste method definitions between instances because 
> Haskell doesn't allow a superclass (or ancestor class) method default to 
> be redefined in a subclass.

The class aliases proposal lists several similar shortcomings of the 
current class system.


> Perhaps there is some reason this can't be done?

Some random thoughts:

How one would write instances? Using your Monad class, does
    instance Monad F where
       return = ...
       (>>=) = ...
automatically define an instance for Applicative?

If it does: What if there already is such an instance? Which one gets 
used for (>>)? The user-defined one or the Monad default? Is separate 
compilation still possible? (If there is no instance right now, one 
might pop out in another module...)

If it does not: How can one define it, without copy-and-pasting the default?


More information about the Haskell-Cafe mailing list