| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Control.Monad.ST.UnsafePerform
- unsafePerformST :: ST s a -> a
Documentation
unsafePerformST :: ST s a -> a Source
This is like unsafePerformIO, but for the ST monad. Highly unsafe, only
use when you really know what you're doing. The same precations as
for unsafePerformIO apply:
If the ST computation wrapped in unsafePerformST performs side
effects, then the relative order in which those side effects take
place (relative to the main I/O trunk, or other calls to
unsafePerformST) is indeterminate. Furthermore, when using
unsafePerformST to cause side-effects, you should take the following
precautions to ensure the side effects are performed as many times as
you expect them to be. Note that these precautions are necessary for
GHC, but may not be sufficient, and other compilers may require
different precautions:
- Use
{-# NOINLINE foo #-}as a pragma on any functionfoothat callsunsafePerformST. If the call is inlined, the S/T may be performed more than once. - Use the compiler flag
-fno-cseto prevent common sub-expression elimination being performed on the module, which might combine two side effects that were meant to be separate. - Make sure that the either you switch off let-floating (
-fno-full-laziness), or that the call tounsafePerformSTcannot float outside a lambda. For example, if you say:f x = unsafePerformST (newSTRef [])you may get only one reference cell shared between all calls tof. Better would bef x = unsafePerformST (newSTRef [x])because now it can't float outside the lambda.
|