blob: 0bfc90fe1a9a49f02ac48a2926793a7731769c48 (
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
|
-- test reification of local definitions
{-# LANGUAGE CPP #-}
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH.Syntax
import System.IO
-- Sidestep the staging restriction
-- printTypeOf :: String -> Q ()
#define printTypeOf(n) (addModFinalizer $ do \
{ VarI _ t _ <- reify (mkName (n)) \
; runIO $ hPutStrLn stderr (n ++ " :: " ++ show t) \
})
main :: IO ()
main = print (f 1 "", g 'a' 2, h True 3)
where
f xf yf = ( xf :: Int
, let ff $(do printTypeOf("yf")
[p| z |]
) = z :: $(do printTypeOf("z")
[t| () |]
)
in $(do printTypeOf("xf")
[| yf :: String |]
)
)
g xg y = ( $(do printTypeOf("xg")
[| y :: Int |]
)
, xg :: Char
)
h xh y = ( $$(do printTypeOf("xh")
[|| y :: Int ||]
)
, xh :: Bool
)
|