[GHC] #5462: Deriving clause for arbitrary classes
GHC
cvs-ghc at haskell.org
Thu Sep 8 09:31:09 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
---------------------------------+------------------------------------------
Comment(by simonpj):
Standalone deriving is, in effect, ''already'' allowed for any class. You
just write
{{{
instance C a => C (T a) -- No 'where' clause
}}}
(not `deriving instance`, just plain `instance`). Like any instance decl,
this will fill in with the default methods; and if the default methods use
Pedro's new generic-programming infrastructure, the default methods will
do the right thing.
The question for this ticket is: should be able to generate this (where-
clause-less) instance decl by saying `data T a = ... deriving( Generic, C
)`.
You ask "Why would I want to write a class and all the supporting code to
allow it to be derived but not add the DERIVABLE pragma?" By "all the
supporting code" I assume you mean default methods a la Pedro (see
http://www.haskell.org/ghc/dist/current/docs/html/users_guide/type-class-
extensions.html#class-default-signatures). Well, you wouldn't. But what
counts as "you have written all the supporting code"?
Perhaps your proposal is this? A class can appear in a `deriving` clause
if (and only if)
* the class has at least one `default foo :: type` signature, and
* the class has a default method definition for every method
Thus
{{{
class C1 a where -- NO (no default method)
op1 :: a -> a
class C2 a where -- NO (non default method signature)
op2 :: a -> a
op2 x = x
class C3 a where -- YES (both are present)
op3 :: a -> a
default op3 :: Ord a => a -> a
op3 x = x>x
}}}
But I'm not sure whether that is what you meant.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5462#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list