Extend TemplateHaskell test

This commit is contained in:
ryndubei 2024-06-10 14:06:29 +02:00
parent b8006fe0c8
commit 6aa54d64b5
2 changed files with 9 additions and 3 deletions

View File

@ -1,4 +1,4 @@
module Spec.TemplateHaskell.TH (intQQ, oneQ) where
module Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two) where
import Language.Haskell.TH
import Language.Haskell.TH.Quote
@ -9,6 +9,12 @@ oneQ = pure . LitE $ IntegerL one
one :: Integer
one = 1
two :: Int
two = 2
twoQ :: Q Exp
twoQ = pure . VarE $ mkName "two"
intQQ :: QuasiQuoter
intQQ = QuasiQuoter
{ quoteExp = pure . LitE . IntegerL . (zero1 +) . read

View File

@ -5,13 +5,13 @@
module Spec.TemplateHaskell.User where
import Spec.TemplateHaskell.TH (intQQ, oneQ)
import Spec.TemplateHaskell.TH (intQQ, oneQ, twoQ, two)
import GHC.TypeLits (Nat)
newtype T (a :: Nat) = T Int
root :: T [intQQ|1|]
root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int)
root = T $ $(oneQ) + [intQQ|1|] + quote + f (1 :: Int) + $(twoQ)
where
f [intQQ|1|] = 1
f _ = 1