summaryrefslogtreecommitdiff
path: root/tests/examples/ghc86/TH_lookupName.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/examples/ghc86/TH_lookupName.hs')
-rw-r--r--tests/examples/ghc86/TH_lookupName.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/examples/ghc86/TH_lookupName.hs b/tests/examples/ghc86/TH_lookupName.hs
new file mode 100644
index 0000000..4465cf8
--- /dev/null
+++ b/tests/examples/ghc86/TH_lookupName.hs
@@ -0,0 +1,37 @@
+-- test 'lookupTypeName' and 'lookupValueName'
+{-# LANGUAGE TemplateHaskell #-}
+
+import Language.Haskell.TH
+
+import qualified TH_lookupName_Lib
+import qualified TH_lookupName_Lib as TheLib
+
+f :: String
+f = "TH_lookupName.f"
+
+data D = D
+
+$(return [])
+
+main = mapM_ print [
+ -- looking up values
+ $(do { Just n <- lookupValueName "f" ; varE n }),
+ $(do { Nothing <- lookupTypeName "f"; [| "" |] }),
+ -- looking up types
+ $(do { Just n <- lookupTypeName "String"; sigE [| "" |] (conT n) }),
+ $(do { Nothing <- lookupValueName "String"; [| "" |] }),
+ -- namespacing
+ $(do { Just n <- lookupValueName "D"; DataConI{} <- reify n; [| "" |] }),
+ $(do { Just n <- lookupTypeName "D"; TyConI{} <- reify n; [| "" |] }),
+ -- qualified lookup
+ $(do { Just n <- lookupValueName "TH_lookupName_Lib.f"; varE n }),
+ $(do { Just n <- lookupValueName "TheLib.f"; varE n }),
+ -- shadowing
+ $(TheLib.lookup_f),
+ $( [| let f = "local f" in $(TheLib.lookup_f) |] ),
+ $( [| let f = "local f" in $(do { Just n <- lookupValueName "f"; varE n }) |] ),
+ $( [| let f = "local f" in $(varE 'f) |] ),
+ let f = "local f" in $(TheLib.lookup_f),
+ let f = "local f" in $(varE 'f)
+ ]
+