I am beginning to learn Template haskell, so I want create a function that receive a String param that define the name to the function to generate
build_p5 :: String -> [Dec]
build_p5 name =
[ FunD p1
[ Clause [TupP [VarP a,VarP b]] (NormalB (AppE (VarE c) (VarE a))) [FunD c [Clause [VarP a] (NormalB (VarE a)) []]]
]
] where
p1 = mkName name
a = mkName "a"
b = mkName "b"
c = mkName "ident"
to run the definition :
$(build_p5 "hola")
but when I run the program get the following error
Couldn't match type ‘[Dec]’ with ‘Q [Dec]’ Expected type: DecsQ Actual type: [Dec] In the expression: build_p5 "hola"
correct code
build_p2 :: Monad m => String -> m [Dec]
build_p2 name =
return [ FunD p1
[ Clause [TupP [VarP a,VarP b]] (NormalB (AppE (VarE c) (VarE a))) [FunD c [Clause [VarP a] (NormalB (VarE a)) []]]
]
] where
p1 = mkName name
a = mkName "a"
b = mkName "b"
c = mkName "ident"