[Haskell-cafe] Just for a laugh...
Dan Doel
dan.doel at gmail.com
Fri Jun 1 15:11:19 EDT 2007
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
More information about the Haskell-Cafe
mailing list