summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_lookupName.hs
blob: b1c051a7310a8b720a6daea6d81ee554052b2a30 (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
-- test 'lookupTypeName' and 'lookupValueName'

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)
 ]