Haskell' - class aliases

Twan van Laarhoven twanvl at gmail.com
Fri Apr 25 19:50:53 EDT 2008

Simon Peyton-Jones wrote:

> Is this the most up-to-date description of the proposal?
>         http://repetae.net/recent/out/classalias.html

Has anyone looked at my (confusingly named and horribly written) variant?


My idea is to split class aliases into two separate things:

   1. Superclass defaults: allow a class declaration to contain defaults for 
methods from superclasses. Allow an instance declaration to be for multiple 
classes at once, using the most specific defaults:

        instance (FooBar a, Foo a, Bar a)
              -- pick the defaults from FooBar, since it is a subclass
              -- of both Foo and Bar.

   2. Class aliases: simply an alias for zero or more classes.

        class alias FooAndBar a = (Foo a, Bar a)

      In a context FooAndBar a is simply replaced by (Foo a, Bar a). For 
instantiation purposes the class alias could override the default methods as if 
it was a subclass of Foo and Bar. No new methods can be added.
      Alternatively class aliases could be just macros, like type synonyms.

Part 1 applies for instance to the Functor/Applicative/Monad hierarchy, fmap 
could have a default in terms of (>>=).
Part 2 is useful for splitting classes up into smaller bits.


More information about the Haskell-prime mailing list