-{-
%
% (c) The GRASP/AQUA Project, Glasgow University, 1995
%
Standard, unbounded channel abstraction.
\begin{code}
--}
module Channel
(
{- abstract type defined -}
) where
-import GHCbase
-{-
+import IOBase ( IO(..) ) -- Suspicious!
+import ConcBase
+import STBase
\end{code}
A channel is represented by two @MVar@s keeping track of the two ends
are used to handle consumers trying to read from an empty channel.
\begin{code}
--}
data Chan a
= Chan (MVar (Stream a))
data ChItem a = ChItem a (Stream a)
-{-
\end{code}
See the Concurrent Haskell paper for a diagram explaining the
these two @MVar@s with an empty @MVar@.
\begin{code}
--}
newChan :: IO (Chan a)
newChan
newMVar hole >>= \ write ->
return (Chan read write)
-{-
\end{code}
To put an element on a channel, a new hole at the write end is created.
new hole.
\begin{code}
--}
putChan :: Chan a -> a -> IO ()
putChan (Chan read write) val
putMVar read new_rend >>
return ()
-{-
\end{code}
Operators for interfacing with functional streams.
\begin{code}
--}
getChanContents :: Chan a -> IO [a]
getChanContents ch
-------------
putList2Chan :: Chan a -> [a] -> IO ()
putList2Chan ch ls = sequence (map (putChan ch) ls)
+
+\end{code}