[Haskell] deriving with newtypes

Simon Peyton-Jones simonpj at microsoft.com
Wed Apr 7 10:50:11 EDT 2004


| It looks like this lets you use partially applied type classes in a
| deriving clause, always apllying that class to the new type last. This
| looks nice, but wouldn't work so well if your newtype was supposed to
go
| first
| 
| class C a b
| instance Char [a]
| newtype T = T Char deriving C ??
| 
| Maybe a deriving clause should allow full instance heads instead as
well
| as class names, so you could write "deriving C T [a]". (Maybe with
| some restrictions, like ensuring the new type appears, or is one of
the
| class arguments).
| 
| It seems more regular to allow you to derive an instance of a
| multi-paramater typeclass with your class in any position rather than
just
| the last.

Maybe so, but the Haskell 98 
	deriving( Num )
already has a class that is "missing" its last parameter. That's why it
is the way it is currently.  Furthermore, Haskell already has many
places in which the order of type parameters matters. For example, if
you want to declare
	instance Monad (ST s) where...
that only works because ST's type params are in the right order.  

So what you say makes sense, but I think it'd be best to await more
people who actually need the extra expressive power before elaborating
this feature. 

For one thing, I have absolutely no idea how many people use GHC's
newtype-deriving feature. Let me know!

Simon


More information about the Haskell mailing list