On Friday 01 June 2007, Andrew Coppin wrote:
> David Roundy wrote:
> > Note also that you can use unsafePerformIO to safely get pure functions
> > doing both these operations.
>
> I've always been puzzled by this one... how does unsafePerformIO
> circumvent the type system? I don't understand.

import Data.IORef
import System.IO.Unsafe

ref :: IORef a
ref = unsafePerformIO $ newIORef undefined

cast :: a -> b
cast a = unsafePerformIO $ do writeIORef ref a ; readIORef ref

*Main> cast 2 :: Double
-3.824225156758791e-48
*Main>

-- Dan
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to