[Haskell-beginners] Just how unsafe is unsafe

Austin Seipp mad.one at gmail.com
Sun Feb 8 14:43:46 EST 2009


Excerpts from Austin Seipp's message of Sun Feb 08 01:45:45 -0600 2009:
> ... code ...
> 
> Austin

*smacks head*

    import Data.IORef
    import System.IO.Unsafe
    import Control.Monad
    
    cast :: a -> b
    cast x = f where
     f = unsafePerformIO $ do
         writeIORef r [x]
         b <- liftM head $ readIORef r
         return b
     r = unsafePerformIO $ newIORef []


More information about the Beginners mailing list