Problem
Is it possible to generate "pure" Haskell code out of the one including Template Haskell functions?
I want to get the code where all Haskell Template's qutations and splices are expanded? (to feed it into another Haskell compiler (Haste), which does not support Template Haskell yet.)
Example
module TupleReplicate:
tupleReplicate n = do
id <- newName "x"
return $ LamE ([VarP id]) (TupE $ replicate n $ VarE id)
main:
main :: IO ()
main = do
print $(tupleReplicate 3) "x"
return ()
can be expanded to:
main :: IO ()
main = do
print (\x->(x,x,x)) "x"
return ()
The solution using Template Haskell pretty printer can be found here: Preferred method for viewing code generated by Template Haskell
There are also other tools, as answered to a question here: How to create a non-TH package from code generated using Template Haskell?
The result of -ddump-splices
is not always valid haskell code, it is only for the programmer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With