[Haskell-cafe] Source code location in IO?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jun 30 12:26:45 UTC 2017


A year has passed and I have just discovered that you had exactly the same
idea two years before me!

    http://augustss.blogspot.se/2014/04/haskell-error-reporting-with-locations_5.html

On Tue, Jun 21, 2016 at 01:45:13AM +0000, Augustsson, Lennart wrote:
> It's totally compatible with Haskell semantics, since Haskell does not give any semantics to IO.
> Anything can happen when you do IO.  But it's still a bit weird. :)
> 
> -----Original Message-----
> From: Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Tom Ellis
> Sent: 20 June 2016 16:04
> To: haskell-cafe at haskell.org
> Subject: [Haskell-cafe] Source code location in IO?
> 
> 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?


More information about the Haskell-Cafe mailing list