2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[Unsafe]{Module @Unsafe@}
7 These functions have their own module because we definitely don't want
11 {-# OPTIONS -fno-implicit-prelude #-}
27 import {-# SOURCE #-} Error ( error )
30 %*********************************************************
32 \subsection{Unsafe @IO@ operations}
34 %*********************************************************
37 unsafePerformIO :: IO a -> a
38 unsafePerformIO (IO m)
39 = case m realWorld# of
41 IOfail _ e -> error ("unsafePerformIO: I/O error: " ++ show e ++ "\n")
43 unsafeInterleaveIO :: IO a -> IO a
44 unsafeInterleaveIO (IO m) = IO ( \ s ->
50 {-# GENERATE_SPECS _trace a #-}
51 trace :: String -> a -> a
54 ((_ccall_ PreTraceHook sTDERR{-msg-}):: IO ()) >>
55 fputs sTDERR string >>
56 ((_ccall_ PostTraceHook sTDERR{-msg-}):: IO ()) >>
59 sTDERR = (``stderr'' :: Addr)
63 unsafeInterleaveST :: ST s a -> ST s a
64 unsafeInterleaveST (ST m) = ST ( \ s ->
75 SLPJ 95/04: Why @runST@ must not have an unfolding; consider:
79 (a, s') = newArray# 100 [] s
80 (_, s'') = fill_in_array_or_something a x s'
84 If we inline @runST@, we'll get:
87 (a, s') = newArray# 100 [] realWorld#{-NB-}
88 (_, s'') = fill_in_array_or_something a x s'
92 And now the @newArray#@ binding can be floated to become a CAF, which
93 is totally and utterly wrong:
96 (a, s') = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!
99 let (_, s'') = fill_in_array_or_something a x s' in
102 All calls to @f@ will share a {\em single} array! End SLPJ 95/04.
105 runST :: (All s => ST s a) -> a
108 ST m -> case m realWorld# of