[GHC] #2851: Deriving doesn't work when type families are involved

GHC trac at galois.com
Mon Dec 8 12:10:40 EST 2008


#2851: Deriving doesn't work when type families are involved
---------------------------------+------------------------------------------
    Reporter:  guest             |        Owner:                  
        Type:  feature request   |       Status:  closed          
    Priority:  normal            |    Milestone:                  
   Component:  Compiler          |      Version:  6.10.1          
    Severity:  minor             |   Resolution:  invalid         
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Changes (by simonpj):

  * status:  new => closed
  * difficulty:  => Unknown
  * resolution:  => invalid

Comment:

 Well, it's tricky.  The 'deriving' mechanism is supposed to produce nice,
 well-behaved, terminating instances, so it insists (as the H98 report
 says) on producing an instance context whose constraints are of the form
 `(C a)`, where `a` is a type variable.

 Fortunately, GHC has just what you want: standalone deriving.  Try this:
 {{{
 {-# LANGUAGE TypeFamilies, FlexibleContexts,
              UndecidableInstances, StandaloneDeriving #-}

 type family F a :: *

 data D a = D (F a)

 deriving instance Show (F a) => Show (D a)
 }}}
 You get to specify the context for the instance, and GHC adds the code for
 the `Show` methods.  Notice that you have to add `FlexibleContexts` and
 `UndecidableInstances` .... and rightly so.  I find this approach works
 much better than requiring these flags for an instance declaration that
 the user never sees.

 So I'll close this.

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2851#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list