2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[UnsafeST]{Module @UnsafeST@}
7 These functions have their own module because we definitely don't want
11 {-# OPTIONS -fno-implicit-prelude #-}
13 module UnsafeST (unsafeInterleaveST, runST) where
20 unsafeInterleaveST :: ST s a -> ST s a
21 unsafeInterleaveST (ST m) = ST ( \ s ->
32 SLPJ 95/04: Why @runST@ must not have an unfolding; consider:
36 (a, s') = newArray# 100 [] s
37 (_, s'') = fill_in_array_or_something a x s'
41 If we inline @runST@, we'll get:
44 (a, s') = newArray# 100 [] realWorld#{-NB-}
45 (_, s'') = fill_in_array_or_something a x s'
49 And now the @newArray#@ binding can be floated to become a CAF, which
50 is totally and utterly wrong:
53 (a, s') = newArray# 100 [] realWorld#{-NB-} -- YIKES!!!
56 let (_, s'') = fill_in_array_or_something a x s' in
59 All calls to @f@ will share a {\em single} array! End SLPJ 95/04.
62 runST :: (All s => ST s a) -> a
65 ST m -> case m realWorld# of