开发者

Modifying the pretty printer from haskell-src-exts

The haskell-src-exts package has functions for pretty printing a Haskell AST. What I want to do is change its behavior on certain constructors, in my case the way SCC pragmas are printed. So everything else should be printed the default way, only SCCs are handled differ开发者_高级运维ently. Is it possible to do it without copying the source file and editing it, which is what I'm doing now?


Well, the library has done one thing right, using a type class for Pretty. The challenge then is how to select a different instance for the constructors you want to print differently. Ideally, you would just newtype the AST node you care about, and somehow substitute that into the AST.

Now, the problem here is that the Haskell AST exported by the library has its type structure fixed. It doesn't, e.g. use two-level types, which would let you substitute newtypes for parts of the tree. So you would have to redefine the type of the AST down to the node you wish to change the type of.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜