문제

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?
도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top