<div dir="ltr">Dear Alejandro,<br><br>I'd also be interested in this.<div><br></div><div>I haven't had the chance to use `{-# LINE ... #-}` pragmas before, but I do have some experience with TH.</div><div>It might help us to get closer to a solution if you described what the transformation is actually doing, and/or include some examples of before and after transformation. It could at the very least help me understand more of the context.</div><div><br></div><div>Thinking further about the question, it seems to me that as soon as our expression has already been transformed to `Exp` (or `Q Exp`) all positional and formatting information is lost.</div><div>But maybe there is still hope.</div><div>Have you considered using the 'haskell-src-meta' package? And/or using QuasiQuotes to transform "String -> Q Exp"? I have a vague memory that there is a haskell-parsing package or project out there (even if it is not specifically 'haskell-src-meta') that does retain the positional information that you are looking for when parsing from String (or `IsString a`).</div><div><br></div><div>Once we do have line numbers, including them as pragmas seems fairly straightforward as `PragmaD (LineP Int String) :: Dec`</div><div>Source: <a href="https://hackage.haskell.org/package/template-haskell-2.11.0.0/docs/Language-Haskell-TH.html#t:Dec">https://hackage.haskell.org/package/template-haskell-2.11.0.0/docs/Language-Haskell-TH.html#t:Dec</a></div><div><br></div><div>Best Regards,</div><div>Milán</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 18, 2016 at 2:53 PM Alejandro Serrano Mena <<a href="mailto:trupill@gmail.com">trupill@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg">Dear Haskell-café,<br class="gmail_msg"></div><div class="gmail_msg">I am trying to write a small TH module which manipulates Haskell code. Basically, I have a function `transform :: Exp -> Q Exp` which I call this way:<br class="gmail_msg"></div><div class="gmail_msg">> g = $(transform [| map (+1) [1,2,3] |])<br class="gmail_msg"></div><div class="gmail_msg">Since this is a source-to-source transformation, I would like to generate also {-# LINE ... #-} pragmas to point any error back to their original location.<br class="gmail_msg"></div><div class="gmail_msg">My question is: is there any way to obtain the location of sub-expressions inside a `Exp` or `Q Exp`?<br class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Thanks in advance,<br class="gmail_msg"></div><div class="gmail_msg">Alejandro<br class="gmail_msg"></div></div>
_______________________________________________<br class="gmail_msg">
Haskell-Cafe mailing list<br class="gmail_msg">
To (un)subscribe, modify options or view archives go to:<br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br class="gmail_msg">
Only members subscribed via the mailman list are allowed to post.</blockquote></div>