[Haskell-cafe] class default method proposal

Twan van Laarhoven twanvl at gmail.com
Wed Dec 12 13:18:11 EST 2007

Simon Peyton-Jones wrote:
> Concerning (b) here's a suggestion.  As now, require that every instance requires an instance declaration.  So, in the main example of http://haskell.org/haskellwiki/Class_system_extension_proposal, for a new data type T you'd write
>         instance Monad T where
>           return = ...
>           (>>=)  = ...
>         instance Functor T
>         instance Applicative T

Another alternative is to allow multiple classes in an instance declaration:

      instance (Monad T, Functor T, Applicative T) where
            return = ...
            (>>=)  = ...

The advantage is that this makes it more clear where the instances come 
from, especially if a class has multiple sub classes with different 
defaults. It also eliminates tricky issues with importing. Of course 
this needs some (albeit very little) new syntax.

I wrote a proposal a while ago, 


More information about the Haskell-Cafe mailing list