Ticket #1825 (closed merge: fixed)

Opened 4 years ago

Last modified 3 years ago

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: Difficulty: Unknown
Test Case: drvail014, drv021 Blocked By:
Blocking: Related Tickets:

Description

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

yields:

[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

Changed 4 years ago by simonpj

  • owner set to simonpj
  • milestone set to 6.8.2

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.

Changed 4 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)

Changed 4 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.

Changed 4 years ago by simonpj

  • owner changed from simonpj to igloo
  • testcase set to drvail014, drv021
  • type changed from bug to merge

Fixed. Thank you for reporting it.

Merge to stable:

Tue Nov 20 12:57:32 GMT 2007  simonpj@microsoft.com
  * FIX Trac #1825: standalone deriving Typeable

Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Merged

Changed 3 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 3 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.