blob: f5950ef5cb527589b888f68f5869c3eb534af7e5 (
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
|
{-# 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 :: Q Exp
h1 = [| $(litE (integerL 3)) |]
-- Splice inside splice inside bracket
h2 :: Q Exp
h2 = [| $(litE ($(varE 'integerL) 3)) |]
|