[Haskell-cafe] Data.Generics question

Grote Collective grotecollective at gmail.com
Tue Dec 19 05:12:46 EST 2006


Hello all,

I have two datatypes, both representing the same language. However, one is a
"flattened" version of the other. For instance:

data Flattened =
  Const Flattened
  | Sum Flattened Flattened
  | ...
  | IntConst Int
  | RealConst Float
  | BoolConst Bool
  | Void

----

data Term =
    Const Constant
  | Sum Term Term
  | ...

data Constant =
    IntConst Int
  | RealConst Float
  | BoolConst Bool
  | Void


Now I want to create functions to convert between these two datatypes. This
is easy to do but *very* tedious in its most naive approach. However, I
think I can use Data.Generics to make a simple implementation of both
functions. The question is: can I? I think that this conversion is a simple
fold over the structure, changing merely the constructor name (the qualified
name, because the unqualified name is the same), but I cannot seem to
understand from the documentation how to do this...

Thanks in advance,
Mark Smith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061219/2bd161a4/attachment.htm


More information about the Haskell-Cafe mailing list