<div dir="ltr">Dear Haskell-cafe,<div>I'm trying to use Template Haskell to generate patterns in Haskell code, but after a couple of days of trying, I have not come with a solution. I hope somebody could help me.</div><div><br></div><div>My problem is basically that I want something like:</div><div><br></div><div><div>example :: Maybe a -> a</div><div>example $(j "x") = x</div></div><div><br></div><div>to work correctly. The idea of this simple quoter is to generate code similar to:</div><div><br></div><div>example :: Maybe a -> a</div><div>example (Just x_123) = x_123</div><div><br></div><div>that is, to create the "Just" pattern, and to make "x" bind to the same element. Right now my code reads:</div><div><br></div><div><div>j :: String -> Q Pat</div><div>j s = return (ConP 'Just [VarP (mkName s)])</div></div><div><br></div><div>which generated a new variable "x" each time, thus unable to match with the "x" in the RHS. I have also tried with lookupValueName.</div><div><br></div><div>Note that my problem is a bit more complicated, with variable names coming from a different source. However, I think that if I solve this problem where I can make variables in a pattern and in an expression match, I should be able to use them in my complete solution.</div><div><br></div><div>Thanks in advance.</div></div>