Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#1825 closed merge (fixed)

standalone deriving for typeable fails

Reported by: jpbernardy Owned by: igloo
Priority: normal Milestone: 6.8.2
Component: Compiler Version: 6.8.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: drvail014, drv021
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


import Data.Typeable

data D a = C1 a | C2 (D a)
deriving instance Typeable a => Typeable (D a)
--           deriving Typeable

x = show $ typeOf (undefined::D Int)

main = print x


[1 of 1] Compiling Main             ( T.hs, T.o )
ghc-6.8.1: panic! (the 'impossible' happened)
  (GHC version 6.8.1 for i386-unknown-linux):
        No match in record selector Var.tcTyVarDetails

Change History (7)

comment:1 Changed 11 years ago by simonpj

Milestone: 6.8.2
Owner: set to simonpj

Oh bother! The deriving for Typeable is unique. If you use the deriving clause on the data decl, you'll get this instance:

instance Typeable1 D where
  typeOf1 _ = mkTyConApp (mkTyCon "D") []

So that's what the user should write in a standalone deriving clause too. thus

deriving instance Typeable1 D 

(There's a uniform instance for type applications.)

Sadly, GHC 6.8.1 rejects the above because "Typeable1 is not a derivable class".

Ok so this is broken and there's no workaround. I will milestone it for 6.8.1. What I propose is to require you to write "deriving instance Typeable1 D". That's not as obvious as the declaration you started with, but it fits with the current impl, and with the (current) Typeable design; see Section 7.4 of the second SYB paper.

comment:2 Changed 11 years ago by simonpj

PS: a smaller program that generates the error, when compiled with -dcore-lint is:

{-# OPTIONS -dcore-lint -XDeriveDataTypeable -XStandaloneDeriving #-}
module Foo where
data D a = C1 a | C2 (D a)
deriving instance Typeable a => Typeable (D a)

comment:3 Changed 11 years ago by igloo

Is it hard to do the same magic for "deriving instance Typeable ..." that is done for "data ... deriving Typeable"? It seems a bit unpleasant that the same thing doesn't work in both cases.

comment:4 Changed 11 years ago by simonpj

Owner: changed from simonpj to igloo
Test Case: drvail014, drv021
Type: bugmerge

Fixed. Thank you for reporting it.

Merge to stable:

Tue Nov 20 12:57:32 GMT 2007
  * FIX Trac #1825: standalone deriving Typeable

comment:5 Changed 11 years ago by igloo

Resolution: fixed
Status: newclosed


comment:6 Changed 10 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:7 Changed 10 years ago by simonmar

Operating System: UnknownUnknown/Multiple
Note: See TracTickets for help on using tickets.