[Haskell-cafe] Source code location in IO?

Anatoly Yakovenko aeyakovenko at gmail.com
Mon Jun 20 18:14:00 UTC 2016


Source location is typically a preprocessor macro. So it could have the
same semantics as a pure Template Haskell function.
On Mon, Jun 20, 2016 at 10:20 AM Tom Ellis <
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:

> On Mon, Jun 20, 2016 at 05:14:45PM +0200, Erik Hesselink wrote:
> > It feels weird to me that this program transformation produces
> > different output, and I can't seem to think of another IO action that
> > behaves this way. Essentially, you'd want `IO a` to have different
> > semantics from other `a`s, in that let binding it changes what it
> > does.
>
> It's definitely weird, but it seems consistent with some behaviour we see
> around lazy IO, Cf these threads
>
>     https://mail.haskell.org/pipermail/haskell/2009-March/021064.html
>     https://mail.haskell.org/pipermail/haskell/2009-March/021071.html
>
> > However, you can do this with the `qLocation` Template Haskell
> > function in Language.Haskell.TH.Syntax. Does that help?
>
> I meant it more as a sort of theoretical question.
>
> > On 20 June 2016 at 17:03, Tom Ellis
> > <tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
> > > Is it compatible with the semantics of Haskell to have a function
> > >
> > >     sourceLocation :: IO String
> > >
> > > which when run returns the source file location at which it is used?
> For
> > > example, suppose Main.hs is
> > >
> > >     module Main where
> > >
> > >     main = do
> > >        putStrLn =<< sourceLocation
> > >        putStrLn "Hello"
> > >        putStrLn =<< sourceLocation
> > >
> > > It would print the following when run
> > >
> > >     Main.hs:4
> > >     Hello
> > >     Main.hs:6
> > >
> > > and
> > >
> > >     module Main where
> > >
> > >     main = do
> > >        let s = sourceLocation
> > >        putStrLn =<< s
> > >        putStrLn "Hello"
> > >        putStrLn =<< s
> > >
> > > It would print the following when run
> > >
> > >     Main.hs:4
> > >     Hello
> > >     Main.hs:4
> > >
> > > If this is not compatible with the semantics of Haskell, why not?  I
> agree
> > > that the two programs must have the same denotation, but is there
> anything
> > > that requires them to have the same output when run?
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160620/460b629d/attachment.html>


More information about the Haskell-Cafe mailing list