[Haskell-cafe] Source code location in IO?

Augustsson, Lennart Lennart.Augustsson at sc.com
Tue Jun 21 01:45:13 UTC 2016


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?

Tom

_______________________________________________
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.

This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at http://www.standardchartered.com/en/incorporation-details.html

Insofar as this communication contains any market commentary, the market commentary has been prepared by sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied for any other purpose, and is subject to the relevant disclaimers available at http://wholesalebanking.standardchartered.com/en/utility/Pages/d-mkt.aspx

Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction. We may at times also request you to sign on the term sheet to acknowledge in respect of the same.

Please visit http://wholesalebanking.standardchartered.com/en/capabilities/financialmarkets/Pages/doddfrankdisclosures.aspx for important information with respect to derivative products.


More information about the Haskell-Cafe mailing list