summaryrefslogtreecommitdiff
path: root/tests/examples/ghc86/TH_lookupName.hs
blob: 4465cf826a16879b1879ea18d64edbb66ac78de3 (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
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)
 ]