summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_reifyLocalDefs.hs
blob: 53a7f8b665c79ebd171d5d5494866a1e80e92222 (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 = ( $$(liftCode $ do printTypeOf("xh")
                                examineCode [|| y :: Int ||]
                 )
             , xh :: Bool
             )