Question

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

  1. whether there are some good and up to date docs on TH (not the reference on Hackage) or
  2. how to make getBody?
Était-ce utile?

La solution

In general, the way to find the definition of something with TH is using the reify function. However:

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?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top