[Haskell-cafe] Re: syscall, sigpause and EINTR on Mac OSX

Tomasz Zielonka tomasz.zielonka at gmail.com
Sun Dec 11 16:10:04 EST 2005


On Sun, Dec 11, 2005 at 08:37:06PM +0000, Joel Reymont wrote:
> Would you care to elaborate? This has not caused any problems for me  
> so far but this is probably due to my usage.

This is a know danger of using unsafePerformIO and one reason for
"unsafe" in its name.

>From http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise5.html:
> Great care should be exercised in the use of this primitive. Not only
> because of the danger of introducing side effects, but also because
> unsafePerformIO may compromise typing; to avoid this, the programmer
> should ensure that the result of unsafePerformIO has a monomorphic
> type.

If you wonder why, analyze this code and see what happens when you run
it.

    import Control.Concurrent
    import System.IO.Unsafe

    {-# NOINLINE children #-}
    children :: MVar [a]
    children = unsafePerformIO $ newEmptyMVar

    main = do
        putMVar children (["foo", "bar", "baz"])
        l <- takeMVar children
        print (l :: [Integer])

It would be nice if GHC could warn about such situations, at least in
the most simple, recognizable cases. Seems like a good task for a new
GHC developer.

Best regards
Tomasz

-- 
I am searching for a programmer who is good at least in some of
[Haskell, ML, C++, Linux, FreeBSD, math] for work in Warsaw, Poland


More information about the Haskell-Cafe mailing list