TH_tf2.hs 558 Bytes
Newer Older
1
{-# LANGUAGE TypeFamilies #-}
2
{-# LANGUAGE AllowAmbiguousTypes #-}  -- 'bar' is ambiguous
3

4
module TH_tf2 where
5

6
{-
7 8 9 10 11
$( [d| class C a where
         data T a
         foo :: Bool -> T a |] )

$( [d| instance C Int where
12
         data T Int = TInt Bool
13 14 15 16 17
         foo b = TInt (b && b) |] )

$( [d| instance C Float where
         data T Float = TFloat {flag :: Bool}
         foo b = TFloat {flag = b && b} |] )
18
-}
19

20
class D a where
21
         type S a
22
         bar :: S a -> Int
23

24
instance D Int where
25
         type S Int = Bool
26
         bar c = if c then 1 else 2