chp-plus-1.2.0: A set of high-level concurrency utilities built on Communicating Haskell Processes

Control.Concurrent.CHP.Connect.TwoDim

Description

This module contains helper functions for wiring up collections of processes into a two-dimensional arrangement.

Synopsis

Documentation

data FourWay above below left right Source

A data type representing four-way connectivity for a process, with channels to the left and right, above and below.

Constructors

FourWay 

Fields

above :: above
 
below :: below
 
left :: left
 
right :: right
 

Instances

(Eq above, Eq below, Eq left, Eq right) => Eq (FourWay above below left right) 

wrappedGridFour :: (Connectable above below, Connectable left right) => [[FourWay above below left right -> CHP a]] -> CHP [[a]]Source

Wires the given grid of processes (that require four-way connectivity) together into a wrapped around grid (a torus) and runs them all in parallel.

The parameter is a list of rows, and should be rectangular (i.e. all the rows should be the same length). If not, an error will result. The return value is guaranteed to be the same shape as the input.

It is worth remembering that if you have only one row or one column (or both), processes can be connected to themselves, so make sure that if a process is connected to itself (e.g. its left channel connects to its right channel), it is coded such that it won't deadlock -- or if needed, checks for this possibility using sameChannel. Processes may also be connected to each other multiple times -- in a two-wide grid, each process's left channel connects to the same process as its right.

wrappedGridFour_ :: (Connectable above below, Connectable left right) => [[FourWay above below left right -> CHP a]] -> CHP ()Source

Like wrappedGridFour but discards the return values.

data FourWayDiag aboveLeft belowRight aboveRight belowLeft Source

A data type representing four-way diagonal connectivity for a process, with channels above-left, below-right, above-right and below-left.

Constructors

FourWayDiag 

Fields

aboveLeft :: aboveLeft
 
belowRight :: belowRight
 
aboveRight :: aboveRight
 
belowLeft :: belowLeft
 

Instances

(Eq aboveLeft, Eq belowRight, Eq aboveRight, Eq belowLeft) => Eq (FourWayDiag aboveLeft belowRight aboveRight belowLeft) 

type EightWay a b l r al br ar bl = (FourWay a b l r, FourWayDiag al br ar bl)Source

EightWay is simply a synonym for a pair of FourWay and FourWayDiag.

wrappedGridEight :: (Connectable above below, Connectable left right, Connectable aboveLeft belowRight, Connectable belowLeft aboveRight) => [[EightWay above below left right aboveLeft belowRight aboveRight belowLeft -> CHP a]] -> CHP [[a]]Source

Like wrappedGridFour but provides eight-way connectivity.

The note on wrappedGridFour about processes being connected to themselves applies here too -- as does the note about processes being connected to each other multiple times. If you have one row, a process's left, above-left and below-left channels all connect to the same process. If you have a two-by-two grid, a process's four diagonal channels all connect to the same process.

wrappedGridEight_ :: (Connectable above below, Connectable left right, Connectable aboveLeft belowRight, Connectable belowLeft aboveRight) => [[EightWay above below left right aboveLeft belowRight aboveRight belowLeft -> CHP a]] -> CHP ()Source

Like wrappedGridEight but discards the output.