[GHC] #5462: Deriving clause for arbitrary classes
GHC
cvs-ghc at haskell.org
Mon Sep 5 17:23:45 CEST 2011
#5462: Deriving clause for arbitrary classes
---------------------------------+------------------------------------------
Reporter: simonpj | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.2.1
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Currently, you can use a `deriving` clause, or standalone-deriving
declaration, only for
* a built-in class like `Eq` or `Show`, for which GHC knows how to
generate the instance code
* a newtype, via the "newtype-deriving" mechanism.
However, Pedros's new generic-default mechanism means that it makes
perfect sense to write this:
{{{
data T a = ...blah..blah... deriving( Generic )
instance C a => C (T a) -- No 'where' clause
}}}
where C is some random user-defined class. Usually, an instance decl with
no 'where' clause would be pretty useless, but now that we have
[http://www.haskell.org/ghc/dist/current/docs/html/users_guide/type-class-
extensions.html#class-default-signatures default method signatures], in
conjunction with `deriving( Generic )`, the instance ''can'' be useful.
That in turn leads to a desire to say
{{{
data T a = ...blah..blah... deriving( Generic, C )
}}}
which is even more compact. Is the extra compactness worth it?
Presumably we'd only want to do this for some specified classes C, so we'd
need some way to say this at C's declaration site. Something like:
{{{
class C where
op :: a -> a
default op :: blah => a -> a
op = <code for the default method>
{-# DERIVABLE C #-} -- This says you can say
-- data T = ... deriving( C )
}}}
I'm a bit dubious about whether the payoff justifies the cost, but I'm
recording the idea in this ticket.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5462>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list