Personal tools

Unsafe functions

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m (expand)
Current revision (11:45, 8 June 2008) (edit) (undo)
m (Added link to "unsafe" keyword in FFI.)
 
(2 intermediate revisions not shown.)
Line 11: Line 11:
Unsafe functions can break type safety (unsafeCoerce#, unsafePerformIO),
Unsafe functions can break type safety (unsafeCoerce#, unsafePerformIO),
-
interfere with lazy IO (unsafeInterleaveIO), or break paramatericity (seq).
+
interfere with lazy IO (unsafeInterleaveIO), or break [http://en.wikipedia.org/wiki/Parametricity parametricity] (seq).
-
There use (except in the case of <hask>seq</hask>) would require some
+
Their use (except in the case of <hask>seq</hask>) would require some
kind of assurance on the part of the programmer that what they're doing
kind of assurance on the part of the programmer that what they're doing
is safe.
is safe.
 +
 +
"unsafe" is also a keyword which can be used in a [http://haskell.org/haskellwiki/Performance/FFI foreign import declaration].
{{stub}}
{{stub}}
[[Category:Idioms]]
[[Category:Idioms]]

Current revision

There are a number of unsafe functions in the libraries.

  • 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
  • unsafeCoerce# :: a -> b
  • seq :: a -> b -> b

Unsafe functions can break type safety (unsafeCoerce#, unsafePerformIO), interfere with lazy IO (unsafeInterleaveIO), or break parametricity (seq).

Their use (except in the case of
seq
) would require some

kind of assurance on the part of the programmer that what they're doing is safe.

"unsafe" is also a keyword which can be used in a foreign import declaration.

This article is a stub. You can help by expanding it.