-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Concurrent Chans as read/write pairs. Also provides generic Chan pair class. -- -- An implementation of concurrent channels identical to -- Control.Concurrent.Chan, except that the channel is represented as a -- pair, one of which allows only read operations, the other write -- operations. -- -- This makes code easier to reason about (the types strictly delegate -- read/write permission), suggests useful instances (e.g. Functor -- and Contravariant are easily defined) on the chan pairs, and -- simplifies the API. -- -- Furthermore this allows messages sent to channels with no readers to -- be trivially garbage-collected, without relying on inlining -- optimizations. -- -- We also provide a module that defines a class SplitChan which -- defines the basic methods any pair of Chan types should provide, -- allowing easy swapping of Chan implementations. -- -- To use standard Chans with these polymorphic functions, import as -- follows: -- --
--   import Control.Concurrent.Chan hiding (readChan,writeChan,writeList2Chan)
--   import Control.Concurrent.Chan.Class
--   
-- -- When used alongside standard Chans, the Split module can be imported -- qualified like: -- --
--   import qualified Control.Concurrent.Chan.Split as S
--   
-- -- Its interface is mostly backwards compatible with Chan. Note, we do -- not implement the deprecated unGetChan and isEmptyChan functions. -- -- This module is used internally by the simple-actors package. -- -- CHANGES: 0.4.0 -> 0.5.0 -- -- @package chan-split @version 0.5.0 module Control.Concurrent.STM.TChan.Class -- | A class capturing Chan operations in STM. class SplitTChan i o | i -> o, o -> i writeTChan :: SplitTChan i o => i a -> a -> STM () readTChan :: SplitTChan i o => o a -> STM a peekTChan :: SplitTChan i o => o a -> STM a tryPeekTChan :: SplitTChan i o => o a -> STM (Maybe a) tryReadTChan :: SplitTChan i o => o a -> STM (Maybe a) isEmptyTChan :: SplitTChan i o => o a -> STM Bool -- | A class for SplitTChan types that can be instantiated without -- programmer input. e.g. the standard haskell TChan is a -- member of this class, however a bounded chan type that took an -- Int to define the buffer size would not. class SplitTChan i o => NewSplitTChan i o newSplitTChan :: NewSplitTChan i o => STM (i a, o a) instance NewSplitTChan TChan TChan instance NewSplitTChan TMVar TMVar instance SplitTChan TChan TChan instance SplitTChan TMVar TMVar module Control.Concurrent.STM.TChan.Split -- | The input side of an unbounded FIFO channel. data InTChan a -- | The output side of an unbounded FIFO channel. data OutTChan a -- | Create a new write end of a TChan. Use dupTChan to get an -- OutChan that values can be read from. newInTChan :: STM (InTChan a) -- | IO version of newTChan. This is useful for creating -- top-level TChans using unsafePerformIO, because using -- atomically inside unsafePerformIO isn't possible. newSplitTChanIO :: IO (OutTChan a, InTChan a) -- | IO version of newInTChan. newInTChanIO :: IO (InTChan a) -- | Put a data item back onto a channel, where it will be the next item -- read. unGetTChan :: OutTChan a -> a -> STM () -- | Create a duplicate OutChan from an InChan. The -- OutChan starts empty but will receive a copy of all -- subsequent values written. dupTChan :: InTChan a -> STM (OutTChan a) -- | Clone a TChan: similar to dupTChan, but the cloned channel -- starts with the same content available as the original channel. cloneTChan :: OutTChan a -> STM (OutTChan a) instance Typeable1 OutTChan instance Typeable1 InTChan instance Eq (OutTChan a) instance Eq (InTChan a) instance SplitTChan InTChan OutTChan instance NewSplitTChan InTChan OutTChan module Control.Concurrent.Chan.Class -- | A class for chan types with a "write end" and a "read end". A minimal -- complete instance defines readChan and one of writeChan -- or writeList2Chan. class SplitChan i o | i -> o, o -> i where writeList2Chan = mapM_ . writeChan writeChan c = writeList2Chan c . return readChan :: SplitChan i o => o a -> IO a writeList2Chan :: SplitChan i o => i a -> [a] -> IO () writeChan :: SplitChan i o => i a -> a -> IO () -- | A class for SplitChan types that can be instantiated without -- programmer input. e.g. the standard haskell Chan is a -- member of this class, however a bounded chan type that took an -- Int to define the buffer size would not. class SplitChan i o => NewSplitChan i o newSplitChan :: NewSplitChan i o => IO (i a, o a) instance NewSplitChan MVar MVar instance SplitChan MVar MVar instance NewSplitChan Chan Chan instance SplitChan Chan Chan module Control.Concurrent.Chan.Split -- | The "write side" of a chan pair data InChan i -- | The "read side" of a chan pair data OutChan i -- | Return a lazy list representing the contents of the supplied OutChan, -- much like System.IO.hGetContents. getChanContents :: OutChan a -> IO [a] -- | Duplicate an OutChan: the duplicate channel contains any unread -- messages in the original (n.b. this differs from the behavior of -- dupChan in Chan), and data written to the corresponding InChan -- will appear in both, i.e. consuming a value from the copy will have no -- affect on the values in the original OutChan. -- -- (Note that a duplicated channel is not equal to its original. So: -- fmap (c /=) $ dupChan c returns True for all -- c.) dupChan :: OutChan a -> IO (OutChan a) instance Typeable1 InChan instance Typeable1 OutChan instance Eq (InChan i) instance Eq (OutChan i) instance SplitChan InChan OutChan instance NewSplitChan InChan OutChan