Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

ghc - Preferred method for viewing code generated by Template Haskell

As you know, Template Haskell is used to generate various kinds of AST splices programmatically at compile-time.

However, a splice can often be very opaque, and it is often difficult to discern what a splice actually generates. If you run the Q monad for a splice, and the splice is well-typed, you get a showable representation of the generated piece of AST, but this representation can be very difficult to understand, because of its unstructured layout.

What is the preferred method for converting a piece of TH-generated AST into something akin to normal Haskell code, so that the code can be easily read and understood? Can one reconstruct source code from e.g. a given Dec value? Does one have to read the GHC Core code? Is there a way to at least structure the AST so that it becomes more readable (Beyond what e.g. the pretty-show package does)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Are you looking for the -ddump-splices flag to the compiler?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...