[Haskell-cafe] Who generates Haskell code and uses type
information at runtime?
Martin Hofmann
martin.hofmann at uni-bamberg.de
Wed Mar 18 06:31:00 EDT 2009
> GHC is the current state of the art, which will give you a full
> Haskell AST enriched with type information. You can then just modify the
> AST directly.
I experimented with the AST from HscTypes.CoreModule in the ghc api.
However, it seems that this representation is too far away from my
theory. I would prefer something similar as Template Haskell.
> The ghc-api is somewhat sparsely documented
That might be the reason, why I have not seen how it can help me.
> It really depends on what you are trying to do...
Putting in a nutshell, I generalize an extensional defined function
definition into a recursive one. This is done in a number of steps by
modifying expressions and exploiting type information of
sub-expressions. For example:
rev [] = []
rev [a] = [a]
rev [a,b] = [b,a]
rev [a,b,c] = [c,b,a]
~~>
rev x = y
~~>
rev [] = []
rev (x:xs) = (y:ys)
~~>
rev [] = []
rev (x:xs) = (last (x:xs)) : (reverse (x:xs))
The initial set of rules is given by the user (in a file, via IO, ...).
The problem later is to infer the type of an intermediate variable, e.g.
'y'.
Thanks,
Martin
More information about the Haskell-Cafe
mailing list