[Haskell] PROPOSAL: class aliases

Udo Stenzel u.stenzel at web.de
Thu Oct 13 09:58:09 EDT 2005

Simon Peyton-Jones wrote:
> I've considered this before, but never done anything about it because
> superclasses are so close.  Specifically, what is the difference between
> (i)	class (C a, D a) => CD a
> and
> (ii)	class alias CD a = (C a, D a)
> Note that (i) is Haskell 98.

I was about to suggest almost exactly the same.  In particular, John's
proposal could be decomposed into three parts:

1. Allow instance declarations to define methods of superclasses.
   These are simply converted into the appropriate instance declarations
   for the superclasses.

2. Allow class declarations to give defaults for methods in
   superclasses.  Together with (1) they are used in the obvious way.

3. Allow empty instance declarations to be implicitly generated.

As a nice side effect, (1) and (2) together would allow us to cleanly
get rid of the fmap/liftM annoyance:

*> class Functor f where { fmap :: ... }
*> class Functor m => Monad m where { fmap = liftM }

I'm not sure about (3).  I think, to effectively make Foo a synonym for
Bar, we'd need:

*> class Foo a => Bar a
*> instance Foo a => Bar a

If the instance for every type were allowed, Foo and Bar would be
indistinguishable from true synonyms.  Further, if classes with no
methods have no use currently, this "universal instance" could be
compiler generated whenever a class without methods is declared.  Or the
empty class may be treated as a synonym, if that's simpler.  Does this
make any sense?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org//pipermail/haskell/attachments/20051013/bdf6f63a/attachment.bin

More information about the Haskell mailing list