Currently I'm trying to do a translation from a Haskell subset without having to deal with all the parsing, typechecking etc. issues. Documentation didn't help me to figure out a function to get the function's body (all the definitions) by its name.
Context for this call should look something like
fac 0 = 1
fac x = z * fac (x - 1)
getBody = ...
main = do
x <- runQ $ getBody [| fac |]
print x
Does anyone knows
In general, the way to find the definition of something with TH is using the reify
function. However:
You can't use reify
at run-time via runQ
. The information it needs is not available except during compilation.
Currently, using reify
to get function definitions is not implemented due to lack of interest anyway.
Looks like you'll need to find another route. Have you considered using the haskell-src-exts
package for parsing and/or the GHC API or something based on it?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With