Question

So, most quasi-quoters for TemplateHaskell have an option where you can read in a quasi-quoted string from a file, instead of typing it in the brackets like [quoter|... some code ...|] .

I'm wondering, is there an equivalent of this for the normal TemplateHaskell quoting brackets? Namely [e|...|] [t|...|] and [d|...|].

I'm writing a translator which converts Haskell code to Elm, while simultaneously keeping my Haskell declarations, so that I can use Haskell for server-side programming and Elm for Javascript generation. To do this translation, I'd like to be able to read in a Haskell module, traverse the ADT using TemplateHaskell, and generate the translated code as a string, while additionally injecting the Haskell declarations from the module into the code.

I've got this working, but only when I write my Haskell code as [d|some decs|]. I'd like to be able to do the same, but read from an external file.

Was it helpful?

Solution

haskell-src-meta is a library for parsing haskell source to a template haskell AST. Specifically, if you want to read a string from a file, parse it as a Haskell module, you use Language.Haskell.Meta.Parse.parseHsModule

OTHER TIPS

Use the parseDecs in http://hackage.haskell.org/package/haskell-src-meta. [d| lets you capture the right variables a reliably from the place the quote is written |] unlike haskell-src-meta. Maybe that doesn't matter so much in your case?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top