summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_NestedSplices.hs
blob: e16e6da8ff5d312e2573fb9497bc4d3bc15ff6b5 (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
{-# LANGUAGE TemplateHaskell #-}
module TH_NestedSplices where

import Language.Haskell.TH

import TH_NestedSplices_Lib 
-- This import brings in
--   spliceExpr :: String -> Q Exp -> Q Exp
--   declareFun :: String -> Q [Dec]

-- Top level splice without $
declareFun "a" 

-- Splice inside splice
$(declareFun $(stringE "b"))

-- Splice inside splice without outer $
declareFun $(stringE "c")

-- Ordinary splicing
f x = $(spliceExpr "boo" [| x |])

-- Splice inside splice
g x = $(spliceExpr $(litE (stringL "boo")) [| x |])

-- Ordinary splice inside bracket
h1 = [| $(litE (integerL 3)) |]

-- Splice inside splice inside bracket
h2 = [| $(litE ($(varE 'integerL) 3)) |]