문제

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?

도움이 되었습니까?

해결책

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.

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