Proposal for stand-alone deriving declarations?
Björn Bringert
bringert at cs.chalmers.se
Fri Oct 6 10:22:09 EDT 2006
John Hughes wrote:
> What I implemented in GHC is an extension of the proposal below. The
> proposal just mentions:
>
> deriving Class for Type
>
> In GHC I also added a form for newtype deriving of multi-parameter
> type classes:
>
> deriving (Class t1 ... tn) for Type
>
> I think that it's close to what we ended up with when talking about
> it at the Hackathon. My intuition about this syntax is that except
> for the "for Type" part, it looks the same as a normal deriving
> clause. The "for" part is just there to connect it to a data/newtype
> declaration. This lets it pretty much use the normal code for
> deriving declarations.
>
> Stand-alone deriving declarations are currently a little bit weaker
> than normal deriving clauses, since the current implementation does
> not let you reference the type arguments of a newtype in the
> arguments of an MPTC. See my response to Bulat on cvs-ghc at haskell.org
> for more details.
>
> /Björn
>
>>
>>
>>
> A suggestion re syntax:
>
> With the newtype-deriving extension, the instances named in a deriving
> clause are not just class names, but partial applications of class names
> to all but the last argument. Why all but the last one? Because the last
> one is the type being defined. Once deriving clauses are separated from
> type definitions, then there is no type being defined any more--hence
> the need for "for Type" in your syntax, and the introduction of another
> keyword. But why single out one class parameter, once deriving clauses
> are separated from type definitions? Why not simply write the FULL
> application of the class in the deriving list? Thus:
>
> deriving (Eq Foo, Ord Foo)
>
> instead of
>
> deriving (Eq, Ord) for Foo
>
> I find the former syntax clearer and more readable, actually.
>
> John
The exact same thing is currently being discussed on
cvs-ghc at haskell.org, and we seem to have reached a consensus to adopt
the same syntax that you are proposing. Well, I was the only one who
ever like the original syntax, so "reached a consensus" means "everybody
else convinced me".
I'll implement this syntax instead and then write up a Haskell' proposal.
/Björn
More information about the Haskell-prime
mailing list