
G'day all, Just looking at the documentation for System.IO.unsafeInterleaveIO, what exactly is unsafe about it? -- % Andre Pang : trust.in.love.to.save http://www.algorithm.com.au/

On Fri, Jun 10, 2005 at 07:32:42PM +0200, Lennart Augustsson wrote:
Andre Pang wrote:
G'day all,
Just looking at the documentation for System.IO.unsafeInterleaveIO, what exactly is unsafe about it? You pick. :)
It can break referential transparency. It can break type safety.
-- Lennart
Are you sure you're not talking about unsafePerformIO? System.IO.Unsafe.unsafePerformIO :: IO a -> a System.IO.Unsafe.unsafeInterleaveIO :: IO a -> IO a As far as I know unsafeInterleaveIO in general isn't any unsafer than it's "special cases" getContents / hGetContents / readFile / getChanContents. Although fighting lazy IO might occasionally drive someone mad, which could arguably be called "unsafe". Cheers, Remi -- Nobody can be exactly like me. Even I have trouble doing it.

On 10/06/2005, at 11:16 AM, Remi Turk wrote:
Are you sure you're not talking about unsafePerformIO?
System.IO.Unsafe.unsafePerformIO :: IO a -> a System.IO.Unsafe.unsafeInterleaveIO :: IO a -> IO a
[written to Lennert Augustsson]: yes, I think you misread unsafeInterleaveIO as unsafePerformIO, Lennert :)
As far as I know unsafeInterleaveIO in general isn't any unsafer than it's "special cases" getContents / hGetContents / readFile / getChanContents. Although fighting lazy IO might occasionally drive someone mad, which could arguably be called "unsafe".
OK, that's more-or-less what I thought. Thanks Remi! -- % Andre Pang : trust.in.love.to.save http://www.algorithm.com.au/

Andre Pang wrote:
On 10/06/2005, at 11:16 AM, Remi Turk wrote:
Are you sure you're not talking about unsafePerformIO?
System.IO.Unsafe.unsafePerformIO :: IO a -> a System.IO.Unsafe.unsafeInterleaveIO :: IO a -> IO a
[written to Lennert Augustsson]: yes, I think you misread unsafeInterleaveIO as unsafePerformIO, Lennert :)
Indeed I did. :)

Just looking at the documentation for System.IO.unsafeInterleaveIO, what exactly is unsafe about it?
It can create "pure values" that trigger side effects during their evaluation. This can be abused to do IO outside of an IO monad (actually, hGetContents can already be used for that purpose). In the worst case, it can even crash the RTS:
import Control.Concurrent.STM import System.IO.Unsafe
main :: IO () main = atomically =<< unsafeInterleaveIO (atomically $ return $ return ())
Thomas

On Sat, Jun 11, 2005 at 01:55:57AM +0200, Thomas Jäger wrote:
Just looking at the documentation for System.IO.unsafeInterleaveIO, what exactly is unsafe about it?
It can create "pure values" that trigger side effects during their evaluation. This can be abused to do IO outside of an IO monad (actually, hGetContents can already be used for that purpose).
In the worst case, it can even crash the RTS:
import Control.Concurrent.STM import System.IO.Unsafe
main :: IO () main = atomically =<< unsafeInterleaveIO (atomically $ return $ return ())
Thomas
Stares at a core-dump. I wonder whether this would be worth a bug-report, or perhaps a warning in STM's docs about (understandable) undefined behaviour in this case. Interestingly, Tomasz Zielonka's FakeSTM [1] survives it. Groeten, Remi [1] http://www.haskell.org/pipermail/haskell-cafe/2005-March/009389.html darcs get http://www.uncurry.com/repos/FakeSTM/ -- Nobody can be exactly like me. Even I have trouble doing it.
participants (4)
-
Andre Pang
-
Lennart Augustsson
-
Remi Turk
-
Thomas Jäger