[Haskell] PROPOSAL: class aliases
benjamin.franksen at bessy.de
Thu Oct 13 07:46:14 EDT 2005
On Thursday 13 October 2005 12:22, John Meacham wrote:
> On Thu, Oct 13, 2005 at 12:08:27PM +0200, Wolfgang Jeltsch wrote:
> > > We allow new constructs of this form (the exact syntax is
> > > flexible of
> > >
> > > course):
> > > > class alias (Foo a, Bar a) => FooBar a where
> > > > foo = ...
> > >
> > > what this does is declare 'FooBar a' as an alias for the two
> > > constraints 'Foo a' and 'Bar a'. This affects two things.
> > Wouldn't it be better to write it this way:
> > class alias (Foo a, Bar a) = FooBar a where ...
> > (Foo a, Bar a) => FooBar a normally means that a type is an
> > instance of Foo and Bar if it is an instance of FooBar but in the
> > case of aliases, a type is also an instance of FooBar if it is an
> > instance of Foo and Bar.
> Yeah, I totally agree. it would also reduce confusion with
> superclasses and emphasises the fact that the two sides are
> equivalent everywhere. (except instance heads)
> although perhaps
> > class alias FooBar a = (Foo a, Bar a) where ...
> since the new name introduced usually appears to the left of an
> equals sign. This also solves the problems of where to put new
> supertype constraints.
Using '=' instead of '=>', you could even leave out the 'alias':
class FooBar a = (Foo a, Bar a) where ...
More information about the Haskell