summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/TH_NestedSplices.hs
blob: 1af80dbcf90c5aa6a814709e16aefb8f055d3614 (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)) |]