Question

Say I have this:

f x = x + 1

tt2 name o = sequence [valD (varP (mkName name)) (normalB [| f $(varE o) |]) []]

I'd like to convert tt2 to tt:

tt name o = [d| ??? = f $(varE o) |]

I cannot figure out what ??? should be. This is probably because I don't understand how TH works yet. Can someone help?

Was it helpful?

Solution

You're trying to splice a name or a pattern. Unfortunately, this is not possible. Template Haskell only allows splicing expressions, types and declarations, so you're stuck with doing it manually as in your original code.

See GHC #1476 for some of the reasons why pattern splices are not allowed.

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