Boilerplate-free annotation of ASTs in Haskell?

后端 未结 4 963
攒了一身酷
攒了一身酷 2020-12-24 06:53

I\'ve been fiddling around with the Elm compiler, which is written in Haskell.

I\'d like to start implementing some optimizations for it, and part of this involves t

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 07:12

    This question is very similar to a past one talking about the particular annotation of source location. The solution I find most elegant is to re-define Expr and Def to provide a constructor that contains an annotation:

    data Expr = PlusExpr Expr Expr
              | AnnotatedExpr Annotation Expr
              ...
    

提交回复
热议问题