Вопрос

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