blob: e9cd180d4c0e61422db41eb34515d6acb43c5964 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
{-# LANGUAGE RankNTypes, ScopedTypeVariables, StandaloneDeriving, GADTs, GeneralizedNewtypeDeriving, DeriveDataTypeable #-}
module Main where
import Data.Typeable
data Expr a where
Lit :: Typeable a => a -> Expr a
class A a where
mk :: a
class (Typeable a, A a) => B a where
mkExpr :: Expr a
mkExpr = Lit mk
-- dfunAE
instance B a => A (Expr a) where
mk = mkExpr
-- dfunAB
instance A Bool where
mk = True
newtype BOOL = BOOL Bool
deriving (Typeable, A)
instance B Bool
deriving instance B BOOL --dfunBB
showType :: forall a . Expr a -> String
showType (Lit _) = show (typeOf (undefined :: a))
test1 = showType (mk :: Expr BOOL) -- Prints "Bool" (wrong?)
test2 = showType (Lit mk :: Expr BOOL) -- Prints "Main.BOOL" (correct)
main = do { print test1; print test2 }
|