[Haskell] PROPOSAL: class aliases
john at repetae.net
Thu Oct 13 06:22:50 EDT 2005
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)
> 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
> class alias FooBar a = Show a => (Foo a, Bar a) where ...
should do nicely.
if nothing better comes along I will update my copy of the proposal
with this new syntax...
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell