I'm trying to learn some Template Haskell. As an exercise, I wrote a function that can generate things like isLeft
and isRight
(inspired by this question). Here's my humble attempt:
isA connam = do
ConE nam <- connam
nn <- newName "p"
lamE [varP nn] $ caseE (varE nn) [
match (conP nam [wildP]) ( normalB [| True |] ) [],
match wildP ( normalB [| False |] ) []
]
The problem is that I have to write $(isA [| Left |])
instead of the more intuitive isA Left
. Is it possible to get rid of the ugly syntax? I can't seem to find the answer in the documentation.
The function only works with one-argument constructors, but this is for another question.