2 % (c) The AQUA Project, Glasgow University, 1994-1996
4 \section[IOExts]{Module @IOExts@}
6 @IOExts@ provides useful functionality that fall outside the
7 standard Haskell IO interface. Expect the contents of IOExts
8 to be the same for Hugs and GHC (same goes for any other
9 Hugs/GHC extension libraries, unless a function/type is
10 explicitly flagged as being implementation specific
14 {-# OPTIONS -fno-implicit-prelude #-}
21 , IORef -- instance of: Eq
26 , IOArray -- instance of: Eq
63 import PrelHandle ( openFileEx, IOModeEx(..),
64 hSetEcho, hGetEcho, getHandleFd
71 import IO ( hPutStr, hPutChar )
75 unsafePtrEq :: a -> a -> Bool
78 unsafePtrEq = primReallyUnsafePtrEquality
81 case reallyUnsafePtrEquality# a b of
88 newIORef :: a -> IO (IORef a)
89 readIORef :: IORef a -> IO a
90 writeIORef :: IORef a -> a -> IO ()
93 type IORef a = STRef RealWorld a
96 writeIORef = writeSTRef
98 newtype IORef a = IORef (MutableVar RealWorld a)
101 newIORef v = stToIO (newVar v) >>= \ var -> return (IORef var)
102 readIORef (IORef var) = stToIO (readVar var)
103 writeIORef (IORef var) v = stToIO (writeVar var v)
108 newIOArray :: Ix ix => (ix,ix) -> elt -> IO (IOArray ix elt)
109 boundsIOArray :: Ix ix => IOArray ix elt -> (ix, ix)
110 readIOArray :: Ix ix => IOArray ix elt -> ix -> IO elt
111 writeIOArray :: Ix ix => IOArray ix elt -> ix -> elt -> IO ()
112 freezeIOArray :: Ix ix => IOArray ix elt -> IO (Array ix elt)
113 thawIOArray :: Ix ix => Array ix elt -> IO (IOArray ix elt)
116 type IOArray ix elt = STArray RealWorld ix elt
117 newIOArray = newSTArray
118 boundsIOArray = boundsSTArray
119 readIOArray = readSTArray
120 writeIOArray = writeSTArray
121 freezeIOArray = freezeSTArray
122 thawIOArray = thawSTArray
124 newtype IOArray ix elt = IOArray (MutableArray RealWorld ix elt)
128 stToIO (newArray ixs elt) >>= \arr ->
131 boundsIOArray (IOArray arr) = boundsOfArray arr
133 readIOArray (IOArray arr) ix = stToIO (readArray arr ix)
135 writeIOArray (IOArray arr) ix elt = stToIO (writeArray arr ix elt)
137 freezeIOArray (IOArray arr) = stToIO (freezeArray arr)
140 marr <- stToIO (thawArray arr)
141 return (IOArray marr)
146 {-# NOINLINE trace #-}
147 trace :: String -> a -> a
149 trace string expr = unsafePerformIO $ do
153 trace string expr = unsafePerformIO $ do
154 fd <- getHandleFd stderr
155 hPutStr stderr string
157 _ccall_ PostTraceHook fd
162 Not something you want to call normally, but useful
163 in the cases where you do want to flush stuff out of
164 the heap or make sure you've got room enough
170 performGC = _ccall_GC_ performGC