Unsafe Functions

Ashley Yakeley ashley at semantic.org
Tue Apr 25 19:02:29 EDT 2006


I would like to start a discussion on the role of unsafe functions in 
Haskell:

   unsafePerformIO :: IO a -> a
   unsafeInterleaveIO :: IO a -> IO a
   unsafeInterleaveST :: ST s a -> ST s a
   unsafeIOToST :: IO a -> ST s a
   unsafeIOToSTM :: IO a -> STM a
   unsafeFreeze, unsafeThaw,
   unsafePreservingMatrix, unsafeRenderPrimitive

perhaps also

   unsafeForeignPtrToPtr :: ForeignPtr a -> Ptr a
     (which is already under Foreign.*)
   hGetContents :: Handle -> IO String
     (which is lazy rather than unsafe per se)

* Do you use these, and what for?

* Is there safe functionality that can currently only be obtained with them?

* Do you think they should be standardised, and how?

I'm thinking the unsafe functions should be moved from System.IO.Unsafe 
and elsewhere to Unsafe, similar to Foreign.*, to better separate them 
from "real Haskell" conceptually. Also, I would add:

   unsafeCoerce :: a -> b

-- 
Ashley Yakeley, Seattle WA
WWEWDD? http://www.cs.utexas.edu/users/EWD/



More information about the Libraries mailing list