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