Control.Concurrent.CHP.Utils
Description
A collection of useful functions to use with the library.
The most useful operation is pipeline
which you can use to wire up a list
of processes into a line, and run them. The corresponding |->|
operator is
a simple binary version that can be a little more concise. When the pipeline
has channels going in both directions rather than just one, dualPipeline
and/or
|<->|
can be used. Several other variants on these functions are also provided,
including operators to use at the beginning and ends of pipelines.
Most of the functions in this module are superseded or generalised by those in the Control.Concurrent.CHP.Connect module since version 1.7.0, so you should look to use those connectors rather than these, as the connects in this module may be removed at some point in the future.
- wireCycle :: Channel r w => [r a -> w a -> proc] -> CHP [proc]
- wireDualCycle :: (Channel r w, Channel r' w') => [(r a, w' b) -> (r' b, w a) -> proc] -> CHP [proc]
- wirePipeline :: forall a r w proc. Channel r w => [r a -> w a -> proc] -> r a -> w a -> CHP [proc]
- wireDualPipeline :: forall a b r w r' w' proc. (Channel r w, Channel r' w') => [(r a, w' b) -> (r' b, w a) -> proc] -> (r a, w' b) -> (r' b, w a) -> CHP [proc]
- pipeline :: [Chanin a -> Chanout a -> CHP b] -> Chanin a -> Chanout a -> CHP [b]
- dualPipeline :: [(Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP c] -> (Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP [c]
- cycle :: [Chanin a -> Chanout a -> CHP b] -> CHP [b]
- dualCycle :: [(Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP c] -> CHP [c]
- (|->|) :: (a -> Chanout b -> CHP ()) -> (Chanin b -> c -> CHP ()) -> a -> c -> CHP ()
- (|->|^) :: Show b => (a -> Chanout b -> CHP ()) -> (String, Chanin b -> c -> CHP ()) -> a -> c -> CHP ()
- (|<->|) :: (a -> (Chanin b, Chanout c) -> CHP ()) -> ((Chanin c, Chanout b) -> d -> CHP ()) -> a -> d -> CHP ()
- (|<-|) :: (Chanin b -> c -> CHP ()) -> (a -> Chanout b -> CHP ()) -> a -> c -> CHP ()
- (->|) :: (Chanout b -> CHP ()) -> (Chanin b -> c -> CHP ()) -> c -> CHP ()
- (|->) :: (a -> Chanout b -> CHP ()) -> (Chanin b -> CHP ()) -> a -> CHP ()
- (|<->) :: (a -> (Chanin b, Chanout c) -> CHP ()) -> ((Chanin c, Chanout b) -> CHP ()) -> a -> CHP ()
- (<->|) :: ((Chanin b, Chanout c) -> CHP ()) -> ((Chanin c, Chanout b) -> a -> CHP ()) -> a -> CHP ()
Documentation
wireCycle :: Channel r w => [r a -> w a -> proc] -> CHP [proc]Source
Wires given processes up in a forward cycle. That is, the first process writes to the second, and receives from the last. It returns the list of wired-up processes, which you will almost certainly want to run in parallel.
wireDualCycle :: (Channel r w, Channel r' w') => [(r a, w' b) -> (r' b, w a) -> proc] -> CHP [proc]Source
Like wireCycle, but works with processes that connect with a channel in both directions.
This function was added in version 1.4.0.
wirePipeline :: forall a r w proc. Channel r w => [r a -> w a -> proc] -> r a -> w a -> CHP [proc]Source
Wires the given processes up in a forward pipeline. The first process in the list is connected to the given reading channel-end (the first parameter) and the writing end of a new channel, A. The second process is wired up to the reading end of A, and the writing end of the next new channel, B. This proceeds all the way to the end of the list, until the final process is wired to the reading end of Z (if you have 27 processes in the list, and therefore 26 channels in the middle of them) and the second parameter. The list of wired-up processes is returned, which you can then run in parallel.
wireDualPipeline :: forall a b r w r' w' proc. (Channel r w, Channel r' w') => [(r a, w' b) -> (r' b, w a) -> proc] -> (r a, w' b) -> (r' b, w a) -> CHP [proc]Source
Like wirePipeline, but works with processes that connect with a channel in both directions.
This function was added in version 1.4.0.
pipeline :: [Chanin a -> Chanout a -> CHP b] -> Chanin a -> Chanout a -> CHP [b]Source
A specialised version of wirePipeline
. Given a list of processes, composes
them into an ordered pipeline, that takes the channel-ends for the sticking
out ends of the pipeline and gives a process that returns a list of their
results. This is equivalent to wirePipeline
, with the return value fed
to runParallel
.
Added in version 1.0.2.
dualPipeline :: [(Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP c] -> (Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP [c]Source
Like pipeline, but works with processes that connect with a channel in both directions.
This function was added in version 1.4.0.
cycle :: [Chanin a -> Chanout a -> CHP b] -> CHP [b]Source
A specialised version of wireCycle
. Given a list of processes, composes
them into a cycle and runs them all in parallel. This is equivalent to
wireCycle
with the return value fed into runParallel
.
Added in version 1.0.2.
dualCycle :: [(Chanin a, Chanout b) -> (Chanin b, Chanout a) -> CHP c] -> CHP [c]Source
Like cycle, but works with processes that connect with a channel in both directions.
This function was added in version 1.4.0.
(|->|) :: (a -> Chanout b -> CHP ()) -> (Chanin b -> c -> CHP ()) -> a -> c -> CHP ()Source
Process composition. Given two processes, composes them into a pipeline,
like function composition (but with an opposite ordering). The function
is associative. Using wirePipeline will be more efficient than foldl1
(|->|)
for more than two processes.
The type for this process became more specific in version 1.2.0.
(|->|^) :: Show b => (a -> Chanout b -> CHP ()) -> (String, Chanin b -> c -> CHP ()) -> a -> c -> CHP ()Source
Like (|->|), but labels the channel and uses show for the traces.
Added in version 1.5.0.
(|<->|) :: (a -> (Chanin b, Chanout c) -> CHP ()) -> ((Chanin c, Chanout b) -> d -> CHP ()) -> a -> d -> CHP ()Source
Process composition that works with processes that connect with a channel in both directions. Like (|->|), but connects a channel in each direction.
This function was added in version 1.4.0.
(|<-|) :: (Chanin b -> c -> CHP ()) -> (a -> Chanout b -> CHP ()) -> a -> c -> CHP ()Source
The reversed version of the other operator.
The type for this process became more specific in version 1.2.0.
(->|) :: (Chanout b -> CHP ()) -> (Chanin b -> c -> CHP ()) -> c -> CHP ()Source
A function to use at the start of a pipeline you are chaining together with
the |->|
operator.
Added in version 1.2.0.
(|->) :: (a -> Chanout b -> CHP ()) -> (Chanin b -> CHP ()) -> a -> CHP ()Source
A function to use at the end of a pipeline you are chaining together with
the |->|
operator.
Added in version 1.2.0.