chp-1.0.2: An implementation of concurrency ideas from Communicating Sequential ProcessesSource codeContentsIndex
Control.Concurrent.CHP.Arrow
Description

Provides an instance of Arrow for process pipelines. As described in the original paper on arrows, they can be used to represent stream processing, so CHP seemed like a possible fit for an arrow.

Whether this is actually an instance of Arrow depends on technicalities. This can be demonstrated with the arrow law arr id >>> f = f = f >>> arr id. Whether CHP satisfies this arrow law depends on the definition of equality.

  • If equality means that given the same input value, both arrows produce the same corresponding output value, this is an arrow.
  • If equality means you give the arrows the same single input and wait for the single output, and the output is the same, this is an arrow.
  • If equality means that you can feed the arrows lots of inputs (one after the other) and the behaviour should be the same with regards to communication, this is not an arrow.

The problem lies in the buffering inherent in arrows. Imagine if f is a single function. f is effectively a buffer of one. You can feed it a single value, but no more than that until you read its output. However, if you have arr id >>> f, that can accept two inputs (one held by the arr id process and one held by f) before you must accept the output.

I am fairly confident that the arrow laws are satisfied for the definition of equality that given the same single input, they will produce the same single output. If you don't worry too much about the behavioural difference, and just take arrows as another way to wire together a certain class of process network, you should do fine.

All your processes should produce exactly one output per input, or else you will find odd behaviour resulting.

Added in version 1.0.2.

Synopsis
data ProcessPipeline a b
runPipeline :: ProcessPipeline a b -> Chanin a -> Chanout b -> CHP ()
Documentation
data ProcessPipeline a b Source
The type that is an instance of Arrow for process pipelines. See runPipeline.
show/hide Instances
runPipeline :: ProcessPipeline a b -> Chanin a -> Chanout b -> CHP ()Source

Given a ProcessPipeline (formed using its Arrow instance) and the channels to plug into the ends of the pipeline, returns the process representing the pipeline.

The pipeline will run forever (until poisoned) and you must run it in parallel to whatever is feeding it the inputs and reading off the outputs. Imagine that you want a process pipeline that takes in a pair of numbers, doubles the first and adds one to the second. You could encode this in an arrow using:

 runPipeline (arr (*2) *** arr (+1))

Arrows are more useful where you already have processes written that process data and you want to easily wire them together. The arrow notation is probably easier for doing that than declaring all the channels yourself and composing everything in parallel.

Produced by Haddock version 2.3.0