Sorry, meant to send this around, not just to Klaus
Klaus Ostermann wrote:
> Hi all,
> I have a problem which is probably not a problem at all for Haskell experts,
> but I am struggling with it nevertheless.
> I want to model the following situation. I have ASTs for a language in two
> variatns: A "simple" form and a "labelled" form, e.g.
> data SimpleExp = Num Int | Add SimpleExp SimpleExp
> data LabelledExp = LNum Int String | LAdd LabelledExp LabelledExp String
> I wonder what would be the best way to model this situation without
> repeating the structure of the AST.
A trick we use all the time in the implementation of Epigram, for pretty
much the purpose you suggest, is to abstract over a type constructor
which packs recursive nodes. Thus