TH Match quotations
Currently it's possible to quote expressions [| e |] :: ExpQ
, patterns [p| pat |] :: PatQ
, types [t| Ty |] :: TypeQ
and declarations [d| data Bar |] :: DecsQ
.
I think it should be possible to quote "matches":
[m| Just x -> print x |] :: MatchQ
As matches can have binders, that cannot be easily split into pattern and expression (+ where
declarations) quotes, i.e. in
[p| Just x |]
, the x
is fresh, and in [e| print x |]
, we have UnboundVarE x
.
So to construct MatchQ
we need to manually call newName
:
x <- newName "x"
match (conP 'Just [varP x]) (normalB $ appE (varE 'print) (varE x)) []
A lot obscurer than above [m| Just x -> print x |]
.
Edited by Oleg Grenrus