Commit 94d8b995 authored by jpm@cs.ox.ac.uk's avatar jpm@cs.ox.ac.uk
Browse files

Implement poly-kinded Typeable

This patch makes the Data.Typeable.Typeable class work with arguments of any
kind. In particular, this removes the Typeable1..7 class hierarchy, greatly
simplyfing the whole Typeable story. Also added is the AutoDeriveTypeable
language extension, which will automatically derive Typeable for all types and
classes declared in that module. Since there is now no good reason to give
handwritten instances of the Typeable class, those are ignored (for backwards
compatibility), and a warning is emitted.

The old, kind-* Typeable class is now called OldTypeable, and lives in the
Data.OldTypeable module. It is deprecated, and should be removed in some future
version of GHC.
parent dc30d983
......@@ -7,7 +7,7 @@ import Data.Data
import Data.Typeable
instance Typeable InstancesInWrongModule where
typeOf _ = undefined
typeRep _ = undefined
instance Data InstancesInWrongModule where
gfoldl = undefined
......
......@@ -7,4 +7,4 @@ import Data.Data
newtype T f = MkT Int
deriving instance Typeable1 T
deriving instance Typeable T
......@@ -3,16 +3,11 @@ module T3965 where
import Data.Data
data T f e = Inl (f e) deriving (Data, Eq)
data T f e = Inl (f e) deriving (Data, Typeable, Eq)
instance (Typeable1 f) => Typeable1 (T f) where
typeOf1 _ = error "urk"
newtype Expr f = In (f (Expr f)) deriving Typeable
newtype Expr f = In (f (Expr f))
instance Typeable1 f => Typeable (Expr f) where
typeOf _ = error "urk"
deriving instance (Typeable1 a, Data (a (Expr a))) => Data (Expr a)
deriving instance (Typeable a, Data (a (Expr a))) => Data (Expr a)
data Var e = Var String deriving (Data, Eq, Typeable)
......
......@@ -11,7 +11,7 @@ data Test a
deriving instance Eq (Test a)
deriving instance Ord (Test a)
deriving instance Typeable1 Test
deriving instance Typeable Test
deriving instance Data a => Data (Test a)
deriving instance Functor Test
deriving instance Foldable Test
......
......@@ -15,6 +15,7 @@ test('drv014', normal, compile, [''])
test('drv015', normal, compile, [''])
test('drv020', normal, compile, [''])
test('drv021', normal, compile, [''])
test('drv022', normal, compile, [''])
test('deriving-1935', normal, compile, [''])
test('T2378', normal, compile, [''])
test('T2856', normal, compile, [''])
......
......@@ -6,7 +6,7 @@
module ShouldCompile where
import Data.Typeable
import Data.OldTypeable
data T1 a = T1 a
data T2 a b = T2 a b
......
drv021.hs:9:1: Warning:
Module `Data.OldTypeable' is deprecated: Use Data.Typeable instead
drv021.hs:14:19: Warning:
In the use of type constructor or class `Typeable1'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
drv021.hs:15:19: Warning:
In the use of type constructor or class `Typeable2'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
{-# LANGUAGE DeriveDataTypeable #-}
module ShouldFail where
module ShouldCompile where
import Data.Typeable
data A a b c d e f g h i j = A deriving (Typeable)
-- Too many args
-- Many args
data B a b = B (a b) deriving (Typeable)
-- Non type-kind args
\ No newline at end of file
-- Non type-kind args
\ No newline at end of file
T2604.hs:7:35:
Can't make a derived instance of `Typeable (DList a)':
Can't make a derived instance of `Typeable * (DList a)':
You need -XDeriveDataTypeable to derive an instance for this class
In the data declaration for `DList'
T2604.hs:9:38:
Can't make a derived instance of `Typeable (NList a)':
Can't make a derived instance of `Typeable * (NList a)':
You need -XDeriveDataTypeable to derive an instance for this class
In the newtype declaration for `NList'
......@@ -8,7 +8,6 @@ test('drvfail006', reqlib('mtl'), compile_fail, [''])
test('drvfail007', normal, compile_fail, [''])
test('drvfail008', reqlib('mtl'), compile_fail, [''])
test('drvfail009', normal, compile_fail, [''])
test('drvfail010', normal, compile_fail, [''])
test('drvfail011', normal, compile_fail, [''])
test('drvfail012', normal, compile_fail, [''])
test('drvfail013', normal, compile_fail, [''])
......
drvfail010.hs:6:42:
Can't make a derived instance of
`Typeable (A a b c d e f g h i j)':
`A' must have 7 or fewer arguments
In the data declaration for `A'
drvfail010.hs:9:32:
Can't make a derived instance of `Typeable (B a b)':
`B' must only have arguments of kind `*'
In the data declaration for `B'
ERROR "drvfail010.hs":6 - Cannot derive instances of class "Typeable"
......@@ -3,7 +3,7 @@
-- See Trac #1825
module ShouldFail where
import Data.Typeable
import Data.OldTypeable
data T1 a = T1 a deriving( Typeable1 )
......
......@@ -37,7 +37,8 @@ expectedGhcOnlyExtensions = [
"AlternativeLayoutRuleTransitional",
"ExplicitNamespaces",
"TypeHoles",
"EmptyCase" ]
"EmptyCase",
"AutoDeriveTypeable"]
expectedCabalOnlyExtensions :: [String]
expectedCabalOnlyExtensions = ["Generics",
......
......@@ -5,7 +5,7 @@ module T1769 where
import Data.Typeable
data family T a
deriving instance Typeable1 T
deriving instance Typeable T
-- deriving instance Functor T
data instance T [b] = T1 | T2 b
......
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
-- The second version (count2) took ages with GHC 6.12
-- because the typeOf function was not properly memoised
......@@ -44,7 +44,4 @@ main = do
doTime $ count1 x
doTime $ count1 x
data T = MkT
tcname :: TyCon
tcname = mkTyCon "T"
instance Typeable T where { typeOf _ = mkTyConApp tcname [] }
data T = MkT deriving Typeable
......@@ -4,5 +4,5 @@ import Data.Data
data HsExpr i
instance Typeable1 HsExpr
instance Typeable HsExpr
instance Data i => Data (HsExpr i)
......@@ -4,7 +4,7 @@
:set -XDeriveDataTypeable
:set -XStandaloneDeriving
:m + Data.Typeable
:m + Data.OldTypeable
data H = H {h :: String} deriving (Typeable, Show)
......
Top level: Warning:
Module `Data.OldTypeable' is deprecated: Use Data.Typeable instead
<interactive>:10:36: Warning:
In the use of type constructor or class `Typeable'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
<interactive>:14:10:
Can't create hand written instances of Typeable in Safe Haskell! Can only derive them
......
[1 of 2] Compiling UnsafeInfered07_A ( UnsafeInfered07_A.hs, UnsafeInfered07_A.o )
UnsafeInfered07_A.hs:4:1: Warning:
Module `Data.OldTypeable' is deprecated: Use Data.Typeable instead
UnsafeInfered07_A.hs:8:10: Warning:
In the use of type constructor or class `Typeable'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
UnsafeInfered07_A.hs:8:10: Warning:
In the use of type constructor or class `Typeable'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
UnsafeInfered07_A.hs:9:16: Warning:
In the use of `typeOf'
(imported from Data.OldTypeable, but defined in Data.OldTypeable.Internal):
Deprecated: "Use Data.Typeable.Internal instead"
[2 of 2] Compiling UnsafeInfered07 ( UnsafeInfered07.hs, UnsafeInfered07.o )
UnsafeInfered07.hs:4:1:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment