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.

其他提示

The easiest way is to compile (or interpret in GHCi) with -ddump-splices.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top