
Sorry, I sent the email to the wrong place and messed up the code
(it's early :)). Take two:
transform = everywhere (mkT transform')
where transform = (\Term a->Flattened a)
`extT` (Contstant a->Flattened a)
On 12/19/06, Vyacheslav Akhmechet
That should be pretty simple. This code probably won't work, but you can use it as an example to look into this further.
transform everywhere = (mkT transform') where transform = (\Term a->Flattened a) `extT` (Contstant a->Flattened a)
Something like this should work. Look into the docs for more info.
On 12/19/06, Grote Collective
wrote: 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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (1)
-
Vyacheslav Akhmechet