dupChan, -- :: Chan a -> IO (Chan a)
unGetChan, -- :: Chan a -> a -> IO ()
+ isEmptyChan, -- :: Chan a -> IO Bool
+
{- stream interface -}
getChanContents, -- :: Chan a -> IO [a]
writeList2Chan -- :: Chan a -> [a] -> IO ()
) where
import Prelude
-import ConcBase
-import STBase
-import Unsafe ( unsafeInterleaveIO )
+import PrelConc
+import PrelST
+import PrelIOBase ( unsafeInterleaveIO )
\end{code}
A channel is represented by two @MVar@s keeping track of the two ends
putMVar new_read_end (ChItem val read_end)
putMVar read new_read_end
+isEmptyChan :: Chan a -> IO Bool
+isEmptyChan (Chan read write) = do
+ r <- takeMVar read
+ w <- readMVar write
+ let eq = r == w
+ eq `seq` putMVar read r
+ return eq
+
\end{code}
Operators for interfacing with functional streams.
-------------
writeList2Chan :: Chan a -> [a] -> IO ()
-writeList2Chan ch ls = sequence (map (writeChan ch) ls)
+writeList2Chan ch ls = sequence_ (map (writeChan ch) ls)
\end{code}