Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling a String into an Exp with TemplateHaskell

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.

like image 426
Nikita Volkov Avatar asked Oct 21 '25 13:10

Nikita Volkov


1 Answers

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

like image 81
user2407038 Avatar answered Oct 24 '25 13:10

user2407038



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!