Commit 57fca849 authored by chak@cse.unsw.edu.au.'s avatar chak@cse.unsw.edu.au.
Browse files

Template Haskell: two tests for type families

parent 83d56696
{-# OPTIONS -fglasgow-exts #-}
module TH_tf1 where
$( [d| data family T a |] )
$( [d| data instance T Int = TInt Bool |] )
foo :: Bool -> T Int
foo b = TInt (b && b)
$( [d| type family S a |] )
$( [d| type instance S Int = Bool |] )
bar :: S Int -> Int
bar c = if c then 1 else 2
{-# OPTIONS -fglasgow-exts #-}
module TH_tf2 where
import Language.Haskell.TH
$( [d| class C a where
data T a
foo :: Bool -> T a |] )
$( [d| instance C Int where
data T Int = TInt Bool
foo b = TInt (b && b) |] )
$( [d| instance C Float where
data T Float = TFloat {flag :: Bool}
foo b = TFloat {flag = b && b} |] )
$( [d| class D a where
type S a
bar :: S a -> Int |] )
$( [d| instance D Int where
type S Int = Bool
bar c = if c then 1 else 2 |] )
......@@ -133,3 +133,5 @@ test('T2685', extra_clean(['T2685a.hi','T2685a.o']),
test('TH_sections', normal, compile, ['-v0'])
test('TH_tf1', normal, compile, ['-v0'])
test('TH_tf2', normal, compile, ['-v0'])
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