문제

I'm looking for a way to compile a string of a valid Haskell expression code into a TH Exp.

E.g., if there existed an appropriate function, I'd expect it to behave the following way:

> $(theFunctionImLookingFor "\a -> a + 1") 2
3

I've already looked for the implementation of quoteExp :: String -> Q Exp for the underlying QuasiQuoter of [e|..|], but it seems to be magic and there is none.

도움이 되었습니까?

해결책

The function you are looking for is parseExp from the Language.Haskell.Meta.Parse module in the haskell-src-meta package.

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