
2010-10-28 12:09, Dupont Corentin skrev:
I'm also looking at the Atom's DSL to get inspiration. Something I don't understand in it is that it has two languages, on typed:
data E a where VRef :: V a -> E a Const :: a -> E a Cast :: (NumE a, NumE b) => E a -> E b Add :: NumE a => E a -> E a -> E a
etc.
And, along with it, an untyped counterpart:
-- | An untyped term. data UE
= UVRef UV | UConst Const
| UCast Type UE | UAdd UE UE
etc.
What that for? What's the use of having beautiful GADT if you have to maintain an untyped ADT aside??
The general reason for this (I can't speak for Atom specifically) is that the typed representation can be quite hard to work with when you want to transform the expressions. But you can still often limit the use of the untyped representation to the last stages in the backend, which means that you can enjoy the typed representation in the initial stages. In the development version of Feldspar, we use a typed representation combined with type-safe casting using Data.Typeable. Although not ideal, this seems to be better than having two different representations. / Emil