<div dir="ltr">I found some old docs saying that pattern splices are not completely implemented due to this problem with binding.<div>At the end, I used quasi-quotation + haskell-src-exts to achieve the same results. In this case, it seemed to work because quasi-quoters are run before the renamer, instead of after it.</div><div><br></div><div>In any case, thanks very much for your help :)</div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-11-03 15:53 GMT+01:00 Richard Eisenberg <span dir="ltr"><<a href="mailto:eir@cis.upenn.edu" target="_blank">eir@cis.upenn.edu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I just tried<br>
<br>
> foo $( [p| x |] ) = x<br>
<br>
and got that x is unbound on the RHS. This may be a GHC bug if no one here knows how this is supposed to work. I sure don't, but I've never explored pattern splices.<br>
<br>
Richard<br>
<div><div class="h5"><br>
On Nov 3, 2014, at 3:07 AM, Alejandro Serrano Mena <<a href="mailto:trupill@gmail.com">trupill@gmail.com</a>> wrote:<br>
<br>
> Dear Haskell-cafe,<br>
> 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.<br>
><br>
> My problem is basically that I want something like:<br>
><br>
> example :: Maybe a -> a<br>
> example $(j "x") = x<br>
><br>
> to work correctly. The idea of this simple quoter is to generate code similar to:<br>
><br>
> example :: Maybe a -> a<br>
> example (Just x_123) = x_123<br>
><br>
> that is, to create the "Just" pattern, and to make "x" bind to the same element. Right now my code reads:<br>
><br>
> j :: String -> Q Pat<br>
> j s = return (ConP 'Just [VarP (mkName s)])<br>
><br>
> which generated a new variable "x" each time, thus unable to match with the "x" in the RHS. I have also tried with lookupValueName.<br>
><br>
> 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.<br>
><br>
> Thanks in advance.<br>
</div></div>> _______________________________________________<br>
> Haskell-Cafe mailing list<br>
> <a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br>
</blockquote></div><br></div>