6.8 unable to derive with higher-kinded variable (6.6 could)

GHC 6.8 seems unable to derive (some?) instances for data types with higher-kinded variables. GHC 6.6 manages these just fine. See below. What's the story? thanks -m :~/haskell$ cat D.hs data T w = T (w Bool) deriving (Show) data ID x = ID x deriving (Show) main = print (T (ID False)) :~/haskell$ ghci -ignore-dot-files -fallow-undecidable-instances D.hs ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.6.1, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. [1 of 1] Compiling Main ( D.hs, interpreted ) Ok, modules loaded: Main. *Main> main T (ID False) *Main> :q Leaving GHCi. :~/haskell$ ${GHC_682_BIN}/ghci -ignore-dot-files -fallow-undecidable-instances D.hs GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help Loading package base ... linking ... done. [1 of 1] Compiling Main ( D.hs, interpreted ) D.hs:1:0: No instance for (Show (w Bool)) arising from the 'deriving' clause of a data type declaration at D.hs:1:0-48 Possible fix: add an instance declaration for (Show (w Bool)) When deriving the instance for (Show (T w)) Failed, modules loaded: none. Prelude>

| GHC 6.8 seems unable to derive (some?) instances for data types with | higher-kinded variables. GHC 6.6 manages these just fine. See below. | data T w = T (w Bool) deriving (Show) | data ID x = ID x deriving (Show) | main = print (T (ID False)) Look at the instance declaration you'd get instance Show (w Bool) => Show (T w) It's not clear that this leads to terminating instance resolution -- and on occasion it didn't! That's bad for a built-in mechanism like 'deriving'. So I tightened up the rules for derived instances, so the (inferred) context must be classes applied to type variable. Nevertheless, if you write the instance decl yourself, GHC lets you: data T w = T (w Bool) deriving instance Show (w Bool) => Show (T w) This uses the new 'standalone deriving' so that you can write the instance decl, including the context; by saying 'deriving' you ask GHC to fill in the methods in the standard way, which it does. Simon
participants (2)
-
Mike Gunter
-
Simon Peyton-Jones