Re: [GHC] #5462: Deriving clause for arbitrary classes

#5462: Deriving clause for arbitrary classes -------------------------------------+------------------------------------ Reporter: simonpj | Owner: dreixel Type: feature request | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 7.2.1 Resolution: | Keywords: Generics Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #7346 -------------------------------------+------------------------------------ Comment (by dreixel): Replying to [comment:22 lerkok]:
Is there any progress on this ticket? Looks like milestone was changed to 7.6.2. I've got 7.6.3 installed, which does not seem to support such deriving instances. Do I need a particular flag to enable this?
No, this was not implemented yet. But I like the idea, and I think Simon's specification is good (repeating here): ---- 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 }}} ---- Only thing left to answer is how to determine the context (in case of standard deriving; in standalone deriving, the user provides the context). For that, I think that Andres's proposal in #7346 sounds reasonable: ---- I propose that if normal deriving is used, GHC uses the same heuristic for figuring out the class context that it uses for Eq in the case of `*`-kinded classes, and for Functor in the case of `* -> *`-kinded classes. That may not be optimal or even wrong. But in such cases, standalone deriving can still be used. ---- If there is no opposition, I'm happy to have a go at implementing this. I agree with [comment:11 dterei] that Haddock and GHCi support would be desirable too. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/5462#comment:24 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC