[Haskell-cafe] Re: Variants of a recursive data structure

Christian Maeder maeder at tzi.de
Fri Aug 4 09:29:55 EDT 2006

Klaus Ostermann schrieb:
> 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.

How about the following simple parameterization?

data Exp label = LNum Int label
               | LAdd (Exp label) (Exp label) label

type SimpleExp = Exp ()

mkNum i = LNum i ()

type LabelledExp = Exp String

Cheers Christian

More information about the Haskell-Cafe mailing list