[GHC] #7742: StandaloneDeriving on Read fails for GADTs

GHC cvs-ghc at haskell.org
Tue Mar 5 20:31:26 CET 2013


#7742: StandaloneDeriving on Read fails for GADTs
--------------------------------------+-------------------------------------
Reporter:  hoffstaetter               |          Owner:                  
    Type:  bug                        |         Status:  new             
Priority:  normal                     |      Component:  Compiler        
 Version:  7.6.2                      |       Keywords:                  
      Os:  MacOS X                    |   Architecture:  Unknown/Multiple
 Failure:  GHC rejects valid program  |      Blockedby:                  
Blocking:                             |        Related:                  
--------------------------------------+-------------------------------------
 Consider the following code that derives a Read instance for a GADT
 datatype:

 {{{
 data Foo a where
     Foo :: Show a => a -> Foo a
 deriving instance Show (Foo a)
 }}}

 The above code works correctly. However, changing the "Show" constraint to
 "Read" will cause GHC to fail:

 {{{
 data Foo a where
     Foo :: Read a => a -> Foo a
 deriving instance Read (Foo a)
 }}}

 with the error message:

 {{{
     No instance for (Read a)
       arising from a use of `GHC.Read.readPrec'
     In the first argument of `Text.ParserCombinators.ReadPrec.step',
 namely
       `GHC.Read.readPrec'
     In a stmt of a 'do' block:
       a1 <- Text.ParserCombinators.ReadPrec.step GHC.Read.readPrec
     In the second argument of `Text.ParserCombinators.ReadPrec.prec',
 namely
       `do { Text.Read.Lex.Ident "Foo" <- GHC.Read.lexP;
             a1 <- Text.ParserCombinators.ReadPrec.step GHC.Read.readPrec;
             return (Foo a1) }'
     When typechecking the code for  `GHC.Read.readPrec'
       in a standalone derived instance for `Read (Foo a)':
       To see the code I am typechecking, use -ddump-deriv
 }}}

 A workaround is to place an additional Read constraint on the deriving
 clause:

 {{{
 data Foo a where
     Foo :: Read a => a -> Foo a
 deriving instance Read a => Read (Foo a)
 }}}

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



More information about the ghc-tickets mailing list