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?

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top