Source location is typically a preprocessor macro. So it could have the same semantics as a pure Template Haskell function. <br><div class="gmail_quote"><div dir="ltr">On Mon, Jun 20, 2016 at 10:20 AM Tom Ellis <<a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk">tom-lists-haskell-cafe-2013@jaguarpaw.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Jun 20, 2016 at 05:14:45PM +0200, Erik Hesselink wrote:<br>
> It feels weird to me that this program transformation produces<br>
> different output, and I can't seem to think of another IO action that<br>
> behaves this way. Essentially, you'd want `IO a` to have different<br>
> semantics from other `a`s, in that let binding it changes what it<br>
> does.<br>
<br>
It's definitely weird, but it seems consistent with some behaviour we see<br>
around lazy IO, Cf these threads<br>
<br>
    <a href="https://mail.haskell.org/pipermail/haskell/2009-March/021064.html" rel="noreferrer" target="_blank">https://mail.haskell.org/pipermail/haskell/2009-March/021064.html</a><br>
    <a href="https://mail.haskell.org/pipermail/haskell/2009-March/021071.html" rel="noreferrer" target="_blank">https://mail.haskell.org/pipermail/haskell/2009-March/021071.html</a><br>
<br>
> However, you can do this with the `qLocation` Template Haskell<br>
> function in Language.Haskell.TH.Syntax. Does that help?<br>
<br>
I meant it more as a sort of theoretical question.<br>
<br>
> On 20 June 2016 at 17:03, Tom Ellis<br>
> <<a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk" target="_blank">tom-lists-haskell-cafe-2013@jaguarpaw.co.uk</a>> wrote:<br>
> > Is it compatible with the semantics of Haskell to have a function<br>
> ><br>
> >     sourceLocation :: IO String<br>
> ><br>
> > which when run returns the source file location at which it is used?  For<br>
> > example, suppose Main.hs is<br>
> ><br>
> >     module Main where<br>
> ><br>
> >     main = do<br>
> >        putStrLn =<< sourceLocation<br>
> >        putStrLn "Hello"<br>
> >        putStrLn =<< sourceLocation<br>
> ><br>
> > It would print the following when run<br>
> ><br>
> >     Main.hs:4<br>
> >     Hello<br>
> >     Main.hs:6<br>
> ><br>
> > and<br>
> ><br>
> >     module Main where<br>
> ><br>
> >     main = do<br>
> >        let s = sourceLocation<br>
> >        putStrLn =<< s<br>
> >        putStrLn "Hello"<br>
> >        putStrLn =<< s<br>
> ><br>
> > It would print the following when run<br>
> ><br>
> >     Main.hs:4<br>
> >     Hello<br>
> >     Main.hs:4<br>
> ><br>
> > If this is not compatible with the semantics of Haskell, why not?  I agree<br>
> > that the two programs must have the same denotation, but is there anything<br>
> > that requires them to have the same output when run?<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>