Unsafe functions

From HaskellWiki
Revision as of 12:02, 24 September 2024 by Atravers (talk | contribs) (Initial quote replaced)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

[Using the FFI] you can import any C function with a pure type, which also allows you to wreak arbitrary havoc. We enable the user to disguise arbitrary machine code as a Haskell function of essentially arbitrary type. In comparison, unsafePerformIO seems angelic.

Manuel Chakravarty

There are a number of unsafe functions in the libraries.

  • unsafeLocalState :: IO a -> a
  • unsafePerformIO :: IO a -> a
  • inlinePerformIO :: 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

Unsafe functions can:

  • break type safety (unsafeCoerce#, unsafeLocalState, unsafePerformIO),

Their use 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.