Reflections on the Work of C.A.R. Hoare pp 333-369 | Cite as

# On CSP and the Algebraic Theory of Effects

## Abstract

We consider CSP from the point of view of the algebraic theory of effects, which classifies operations as effect *constructors* or effect *deconstructors*; it also provides a link with functional programming, being a refinement of Moggi’s seminal monadic point of view. There is a natural algebraic theory of the constructors whose free algebra functor is Moggi’s monad; we illustrate this by characterising free and initial algebras in terms of two versions of the stable failures model of CSP, one more general than the other. Deconstructors are dealt with as homomorphisms to (possibly non-free) algebras. One can view CSP’s action and choice operators as constructors and the rest, such as concealment and concurrency, as deconstructors. Carrying this programme out results in taking deterministic external choice as constructor rather than general external choice. However, binary deconstructors, such as the CSP concurrency operator, provide unresolved difficulties. We conclude by presenting a combination of CSP with Moggi’s computational λ-calculus, in which the operators, including concurrency, are polymorphic. While the paper mainly concerns CSP, it ought to be possible to carry over similar ideas to other process calculi.

## 15.1 Introduction

We examine Hoare’s CSP [9, 13,29] from the point of view of the algebraic theory of effects [14, 22, 23, 25], a refinement of Moggi’s seminal “monads as notions of computation” [3, 18, 19]. This is a natural exercise as the algebraic nature of both points to a possibility of commonality. In the algebraic theory of effects all operations do not have the same character. Some are effect *constructors*: they create the effects at hand; some are effect *deconstructors*: they respond to effects created. For example, raising an exception creates an effect the exception raised whereas exception-handling responds to effects exceptions that have been raised. It may therefore be interesting, and even useful, to classify CSP operators as constructors or deconstructors. Considering CSP and the algebraic theory of effects together also raises the possibility of combining CSP with functional programming in a principled way, as Moggi’s monadic approach provides a framework for the combination of computational effects with functional programming. More generally, although we mainly consider CSP, a similar exercise could be undertaken for other process calculi as they have a broadly similar algebraic character.

The theory of algebraic effects starts with the observation that effect constructors generally satisfy natural equations, and Moggi’s monad *T* is precisely the free algebra monad for these equations (an exception is the continuations monad, which is of a different character). Effect deconstructors are treated as homomorphisms from the free algebra to another algebra, perhaps with the same carrier as the free algebra but with different operations. These operations can be given by combinations of effect constructors and previously defined deconstructors. The situation is much like that of primitive recursive definitions, although we will not present a formal definitional scheme.

We mainly consider that part of CSP containing action, internal and external choice, deadlock, relabelling, concealment, concurrency and interleaving, but not, for example, recursion (we do, albeit briefly, consider the extension with termination and sequencing). The evident constructors are then action prefix, and the two kinds of choice, internal and external, the latter together with deadlock. The evident deconstructors are relabelling, concealment, concurrency and interleaving. There is, however, a fly in the ointment, as pointed out in [25]. Parallel operators, such as CSP’s concurrency and interleaving, are naturally binary, and respond to effects in both arguments. However, the homomorphic approach to deconstructors, as sketched above, applies only to unary deconstructors, although it is possible to extend it to accommodate parameters and simultaneous definitions. Nonetheless, the natural definitions of concurrency and interleaving do not fall within the homomorphic approach, even in the extended sense. This problem has nothing to do with CSP: it applies to all examples of parallelism of which we are aware.

Even worse, when we try to carry out the above analysis for CSP, it seems that the homomorphic approach cannot handle concealment. The difficulty is caused by the fact that concealment does not commute with external choice. Fortunately this difficulty can be overcome by changing the effect constructors: we remove external choice and action prefix and replace them by the deterministic external choice operator (*a*_{1} → *P*(*a*_{1})∣*…*∣*a*_{n} → *P*(*a*_{n})), where the *a*_{i} are all different. Binary external choice then becomes a deconstructor.

With that we can carry out the program of analysis, finding only the expected difficulty in dealing with concurrency and interleaving. However, it must be admitted that the *n*-ary operators are somewhat clumsy to work with, and it is at least a priori odd to take binary external choice as a deconstructor. On the other hand, in [13] Section 1.1.3 Hoare writes:

The definition of choice can readily be extended to more than two alternatives, e.g.,Note that the choice symbol ∣ is$$(x \rightarrow P\mid y \rightarrow Q\mid \ldots \mid z \rightarrow R)$$notan operator on processes; it would be syntactically incorrect to writeP∣Q, for processesPandQ. The reason for this rule is that we want to avoid giving a meaning towhich appears to offer a choice of first event, but actually fails to do so.$$(x \rightarrow P\mid x \rightarrow Q)$$

which might be read as offering some support to a treatment, which takes deterministic external choice as a primitive (here = constructor), rather than general external choice. On our side, we count it as a strength of the algebraic theory of effects that it classifies effect-specific operations and places constraints on them: that they either belong to the basic theory or must be defined according to a scheme that admits inductive proofs.

Turning to the combination with functional programming, consider Moggi’s computational λ-calculus. Just as one accommodates imperative programming within functional programming by treating commands as expressions of type unit, so it is natural to treat our selection of CSP terms as expressions of type emptyas they do not terminate normally, only in deadlock. For process languages such as ACP [4,5] which do have the possibility of normal termination, or CSP with such a termination construct, one switches to regarding process terms as expressions of type unit, when a sequencing operator is also available.

*T*(

*X*), it is natural to treat them as polymorphic constructs, rather than just as process combinators. For example, one could have a binary construction for internal choice, with typing rule:

*M*and

*N*are evaluated concurrently, terminating normally only if they both do, when the pair of results returned individually by each is returned.

In the case of CSP a functional programming language CSPM incorporating CSP processes has been given by Scattergood [31]; it is used by most existing CSP tools including the Failures Divergences Refinement Checker (FDR), see [28]. Scattergood’s CPSM differs from our proposal in several respects. Most significantly, processes are not treated on a par with other expressions: in particular, they cannot be taken as arguments in functions, and CSP constructors and deconstructors are only available for processes. It remains to be seen if such differences are of practical relevance.

In Section 15.3 we take deadlock, action, binary internal and external choice as the constructors. We show, in Theorem 1, that, with the standard equational theory, the initial algebra is the “finitary part” of the original Brookes-Hoare-Roscoe failures model [9]; which is known to be isomorphic to the finitary, divergence- and \(\surd\)-free part of the failures/divergences model, as well as the finitary, divergence- and \(\surd\)-free part of the stable failures model, both of which are described in [29]. In Section 15.4 we go on to consider effect deconstructors, arriving at the difficulty with concealment and illustrating the problems with parallel operators in the (simpler) context of Milner’s synchronisation trees. A reader interested in the problem of dealing with parallel operators algebraically need only read this part, together with [25].

We then backtrack in Section 15.5, making a different choice of constructors, as discussed above, and giving another characterisation of the finitary failures model as an initial algebra in Theorem 3. With that, we can carry out our programme, failing only where expected: with the binary deconstructors. In Section 15.6 we add a zero for the internal choice operator to our algebra; this can be interpreted as divergence in the stable failures model, and permits the introduction of a useful additional deterministic external choice constructor. Armed with this tool, in Section 15.7, we look at the combination of CSP and functional programming, following the lines hinted at above. In order to give a denotational semantics we need, in Theorem 7, to characterise the free algebras rather than just the initial one.

As remarked above, termination and sequencing are accommodated within functional programming via the type unit ; in Section 15.7.1 we therefore also give a brief treatment of our fragment of CSP extended with termination and sequencing, modelling it in the free algebra over the one-point set.

Section 15.8 contains a brief discussion of the general question of combining process calculi, or parallelism with a global store, with functional programming. The case of CSP considered here is just one example of the many such possible combinations. Throughout this paper we do not consider recursion; this enables us to work within the category of sets. A more complete treatment would deal with recursion working within, say, the category of ω-cpos (i.e., partial orders with lubs of increasing ω-sequences) and continuous functions (i.e., monotone functions preserving lubs of increasing ω-sequences). This is discussed further in Section 15.8. The appendix gives a short presentation of Moggi’s computational λ-calculus.

## 15.2 Technical Preliminaries

We give a brief sketch of finitary equational theories and their free algebra monads. For a fuller explanation see, e.g., [8, 2]. Finitary equational theories Th are derived from a given set of axioms, written using a signature *Σ* consisting of a set of operation symbols op: *n*, together with their arities *n* ≥ 0. One forms terms *t* from the signature and variables and the axioms then consist of equations *t* = *u* between the terms; there is a natural equational logic for deducing consequences of the axioms; and the theory consists of all the equations derivable from the axioms. A *ground* equation is one where both terms are *closed*, meaning that they contain no variables.

*Σ-algebra*is a structure \(\mathcal{A} = (X,{(\mathrm{{op}}_{\mathcal{A}}\! :\! {X}^{n} \rightarrow X)}_{\mathrm{op}:n\in \Sigma })\); we say that

*X*is the

*carrier*of \(\mathcal{A}\) and the \(\mathrm{{op}}_{\mathcal{A}}\) are its

*operations*. We may omit the subscript on operations when the algebra is understood. When we are thinking of an algebra as an algebra of processes, we may say “operator” rather than “operation.” A homomorphism between two algebras is a map between their carriers respecting their operations; we therefore have a category of

*Σ*-algebras.

Given such a *Σ*-algebra, every term *t* has a *denotation* [[*t*]](ρ), an element of the carrier, given an assignment ρ of elements of the carrier to every variable; we often confuse terms with their denotation. The algebra *satisfies* an equation *t* = *u* if *t* and *u* have the same denotation for every such assignment. If \(\mathcal{A}\) satisfies all the axioms of a theory Th, it is called a Th-algebra; the Th-algebras form a subcategory of the category of *Σ*-algebras. Any equation provable from the axioms of a theory Th is satisfied by any Th-algebra. We say that a theory Th is *(ground) equationally complete* with respect to a Th-algebra if a (ground) equation is provable from Th if, and only if, it is satisfied by the Th-algebra.

*T*

_{Th}on the category of sets, as well as operations

*X*and op:

*n*∈

*Σ*, such that (

*T*

_{Th}(

*X*), (op

_{X} :

*X*

^{n}→

*X*)

_{op: n ∈ Σ}) is the free Th-algebra over

*X*. Although

*T*

_{Th}(

*X*) is officially just a set, the carrier of the free algebra, we may also use

*T*

_{Th}(

*X*) to denote the free algebra itself. In the above example the monad is the finite powerset monad:

_{X}and Stop

_{X}being union and the empty set, respectively.

## 15.3 A First Attempt at Analysing CSP

We consider the fragment of CSP with deadlock, action prefix, internal and external choice, relabelling and concealment, and concurrency and interleaving. Working over a fixed alphabet *A* of *actions*, we consider the following operation symbols:

**Deadlock**

**Action**

**Internal and External Choice**

**Relabelling and Concealment**

*relabelling functionf* :

*A*→

*A*and action

*a*. If

*A*is infinite, this makes the syntax infinitary; as that causes us no problems, we do not avoid it.

**Concurrency and Interleaving**

□, Stop is a semilattice with a zero (i.e., the above axioms for a semilattice with a zero).

⊓is a semilattice (i.e., the axioms stating the associativity, commutativity and idempotence of ⊓).

- □ and ⊓distribute over each other:$$x\square (y \sqcap z) = (x\square y) \sqcap(x\square z)\quad \quad x \sqcap(y\square z) = (x \sqcap y)\square (x \sqcap z)$$
- Actions distribute over ⊓:and:$$a \rightarrow(x \sqcap y) = a \rightarrow x \sqcap a \rightarrow y$$$$a \rightarrow x\square a \rightarrow y = a \rightarrow x \sqcap a \rightarrow y$$

All these axioms are mathematically natural except the last which involves a relationship between three different operators.

We adopt some useful standard notational abbreviations. For *n* ≥ 1 we write ⊓_{i = 1}^{n}*t*_{i} to abbreviate *t*_{1} ⊓*…* ⊓*t*_{n}, intending *t*_{1} when *n* = 1. We assume that parentheses associate to the left; however as ⊓is associative, the choice does not matter. As ⊓is a semilattice, we can even index over nonempty finite sets, as in ⊓_{i ∈ I}*t*_{i}, assuming some standard ordering of the *t*_{i} without repetitions. As □ is a semilattice with a zero, we can adopt analogous notations □ _{i = 1}^{n}*t*_{i} and □ _{i ∈ I}*t*_{i} but now also allowing *n* to be 0 and *I* to be *∅*.

*t*⊑

*u*as an abbreviation for

*t*⊓

*u*=

*t*; then, as □ distributes over ⊓, it is monotone with respect to ⊑:that is, if

*x*⊑

*x′*and

*y*⊑

*y′*then

*x*□

*y*⊑

*x′*□

*y′*. (We mean all these in a formal sense, for example, that if

*t*⊑

*u*and

*u*⊑

*v*are provable, so is

*t*⊑

*v*, etc.) We note the following, which is equivalent to the distributivity of ⊓over □, given that ⊓and □ are semilattices, and the other distributivity, that □ distributes over ⊓:

*x*⊓(

*y*□

*z*) ⊑ (

*x*□

*y*). Using this one can derive another helpful equation:

We next rehearse the original refusal sets model of CSP, restricted to finite processes without divergence; this provides a convenient context for identifying the initial model of CSP ( □ ) in terms of failures.

*failure (pair)*is a pair (

*w*,

*W*) with

*w*∈

*A*

^{∗}and

*W*⊆

_{fin}

*A*. For every set

*F*of failure pairs, we define its set of

*traces*to be

*w*∈ tr

_{F}we define its set of

*futures*to be:

*refusal setF*(aka a

*failure set*) is a set of failure pairs, satisfying the following conditions:

- 1.
ε ∈ tr

_{F} - 2.
*wa*∈ tr_{F}⇒*w*∈ tr_{F} - 3.
(

*w*,*W*) ∈*F*∧*V*⊆*W*⇒ (*w*,*V*) ∈*F* - 4.
(

*w*,*W*) ∈*F*∧*a*∉fut_{F}⇒ (*w*,*W*∪{*a*}) ∈*F*

A refusal set is *finitary* if its set of traces is finite.

*f*on sequences and sets of actions, and where

*w*∖

*a*is obtained from

*w*by removing all occurrences of

*a*, and where

*u*∣

*v*is the set of interleavings of

*u*and

*v*.

### Lemma 1.

*Let F be a finitary refusal set. Then for every w ∈**tr*_{F}*there are V*_{1}*,…,V*_{n}*⊆**fut*_{F}*(w), including**fut*_{F}*(w), such that (w,W) ∈ F iff W ∩ V*_{i}*= ∅ for some i ∈ {1,…,n}.*

### Proof.

The closure conditions imply that (*w*, *W*) is in *F* iff (*w*, *W* ∩ fut_{F}(*w*)) is. Thus we only need to be concerned about pairs (*w*, *W*) with *W* ⊆ fut_{F}(*w*). Now, as fut_{F}(*w*) is finite, for any relevant (*w*, *W*) ∈ *F*, of which there are finitely many, we can take *V* to be fut_{F}(*w*) ∖ *W*, and we obtain finitely many such sets. As (*w*, *∅*) ∈ *F*, these include fut_{F}(*w*).

### Lemma 2.

*All finitary refusal sets are definable by closed* CSP *(□) terms*

### Proof.

*F*be a finitary refusal set. We proceed by induction on the length of the longest trace in

*F*. By the previous lemma there are sets

*V*

_{1},

*…*,

*V*

_{n}, including fut

_{F}(ε), such that (ε,

*W*) ∈

*F*iff

*W*∩

*V*

_{i}=

*∅*for some

*i*∈ { 1,

*…*,

*n*}. Define

*F*

_{a}, for

*a*∈ fut

_{F}(ε), by:

*F*

_{a}is a finitary refusal set, and that

*F*

_{a}is strictly shorter than the longest one in

*F*, the proof concludes, employing the induction hypothesis.

*ℒ*be a collection of sets; we say it is

*saturated*if whenever

*L*⊆

*L′*⊆ ⋃

*ℒ*, for

*L*∈

*ℒ*then

*L′*∈

*ℒ*. Then a closed CSP ( □ )-term

*t*is in

*normal form*if it is of the form:

*ℒ*is a finite non-empty saturated collection of finite sets of actions and each term

*t*

_{a}is in normal form. Note that the concept of normal form is defined recursively.

### Proposition 1.

CSP *(□) is ground equationally complete with respect to*\({\mathcal{R}\!}_{f}\)*.*

### Proof.

Every term is provably equal in CSP ( □ ) to a term in normal form. For the proof, follow that of Proposition A6 in [10]; alternatively, it is a straightforward induction in which Eqs. 15.1 and 15.2 are helpful. Further, it is an immediate consequence of Lemma 4.8 in [10] that if two normal forms have the same denotation in \({\mathcal{R}\!}_{f}\) then they are identical (and Lemma 6 below establishes a more general result). The result then follows.

### Theorem 1.

*The finitary refusal sets algebra*\({\mathcal{R}\!}_{f}\)*is the initial* CSP *(□) algebra.*

### Proof.

Let the initial such algebra be I. There is a unique homomorphism \(h\! :\!\mathrm{ I} \rightarrow {\mathcal{R}\!}_{f}\). By Lemma 2, *h* is a surjection. By the previous proposition, \({\mathcal{R}\!}_{f}\) is complete for equations between closed terms, and so *h* is an injection. So *h* is an isomorphism, completing the proof.

## 15.4 Effect Deconstructors

*deconstructors*, such as exception handlers, is given using homomorphisms from free algebras. In this case we are interested in

*T*

_{CSP ( □ )}(

*∅*). This is the initial CSP ( □ ) algebra, \({\mathcal{R}\!}_{f}\), so given a CSP ( □ ) algebra:

**Relabelling** We now seek to define *f*( − ) : *T*_{CSP ( □ )}(*∅*) → *T*_{CSP ( □ )}(*∅*) homomorphically. Define an algebra *Rl* on *T*_{CSP ( □ )}(*∅*) by putting, for refusal sets *F*, *G*:

*F*,

*G*:

*h*

_{Rl}by a “

*principle of equational recursion*,” but one must remember to verify that the implicit algebra obeys the required equations.

*h*

_{Rl}to interpret relabelling. We then immediately recover the familiar CSP laws:

**Concealment**There is a difficulty here. We do not have that

*a*

_{i}is

*a*. Furthermore, there is no direct definition of concealment via an equational recursion, i.e., there is no suitable choice of algebra, \({\square }_{\mathcal{A}}\) etc. For, if there were, we would have:

*a*does not occur in any trace of

*F′*or

*G′*we would have:

*a*certainly does not occur in any trace of

*F*∖

*a*or

*G*∖

*a*and so we would have:

### 15.4.1 Concurrency Operators

Before trying to recover from the difficulty with concealment, we look at a further difficulty, that of accommodating binary deconstructors, particularly parallel operators. We begin with a simple example in a strong bisimulation context, but rather than a concurrency operator in the style of CCS we consider one analogous to CSP’s ∣∣.

*a*. −, for

*a*∈

*A*, a nullary NIL and a binary sum +. The axioms are that + is a semilattice with zero NIL ; the initial algebra is then that of finite synchronisation trees

*ST*. Every synchronisation tree τ has a finite depth and can be written as

*n*≥ 0, where the τ

_{i}are also synchronisation trees (of strictly smaller depth), and where no pair (

*a*

_{i}, τ

_{i}) occurs twice. The order of writing the summands makes no difference to the tree denoted.

_{i}

*a*

_{i}. τ

_{i}and τ

*′*= ∑

_{j}

*b*

_{j}. τ

_{j}by induction on the depth of τ (or τ

*′*):

^{a}with

*x*,

*y*,

*z*varying over

*ST*:

*ST*→

*ST*×

*ST*. Informally we would write such clauses as:

*x*,

*y*, on the left for ∣∣ and on the right for ∣∣

^{a}. However:

*x*, (twice) switches places with the parameter

*z*.

^{a}have a unique solution: the expected synchronisation operator ∣∣, and the functions ∣∣

^{a}defined on synchronisation trees τ and τ

*′*= ∑

_{j}

*b*

_{j}. τ

_{j}by:

A different correct definition in the equational recursion format

Another algebraic format into which the correct definition fits

^{a}. The reason is that there is no binary operator □

*′*on (finitary) failure sets such that, for all

*F*,

*G*,

*H*we have:

*F*and

*F′*, choose

*G*such that

*F*∣∣

*G*=

*F*,

*F′*∣∣

*G*=

*F′*and (

*F*□

*F′*)∣∣

*G*= (

*F*□

*F′*). Then, substituting into the above equation, we obtain that

*F*□

*F′*=

*F*□

*′F′*and so the above equation yields distributivity, which, in fact, does not hold. As in the case of concealment, there may nonetheless be an indirect definition of ∣∣.

A similar difficulty obtains for the CSP interleaving operator. It too does not commute with □, and it too does not have any direct definition (the argument is like that for the concurrency operator but a little simpler, taking *G* = Stop). As in the case of the concurrency operator, there may be an indirect definition.

## 15.5 Another Choice of CSP Effect Constructors

*a*

_{i}(

*i*= 1,

*n*), the following equation holds between refusal sets:

*j*≤

*n*. Taken together with Eq. (15.4), this suggests a recursive definition in terms of deterministic external choice. We therefore now change our choice of constructors, replacing binary external choice, action prefix and deadlock by deterministic external choice.

So as our second signature for CSP we take a binary operation symbol ⊓of internal choice and, for any *deterministic action sequence*\(\vec{a}\) (i.e., any sequence of actions *a*_{i} (*i* = 1, *n*), with the *a*_{i} all different and *n* ≥ 0), an *n*-ary operation symbol \({\square }_{\vec{a}}\) of deterministic external choice. We write \({\square }_{\vec{a}}({t}_{1},\ldots,{t}_{n})\) as □ _{i = 1}^{n}*a*_{i}*t*_{i} although it is more usual to use Hoare’s notation \(({a}_{1} \rightarrow{t}_{1}\mid \ldots \mid {a}_{n} \rightarrow{t}_{n})\); we also use Stop to abbreviate \({\square }_{\vec{a}}()\).

*…*,

*n*}. Given this, we are justified in writing deterministic external choices over finite, possibly empty, sets of actions, □

_{a ∈ I}

*at*

_{a}, assuming some standard ordering of pairs (

*a*,

*t*

_{a}) without repetitions.

*a*

_{1}→

*t*

_{1}) □ □

_{i = 2}

^{n}

*a*

_{i}

*t*

_{i}for □

_{i = 1}

^{n}

*a*

_{i}

*t*

_{i}(for

*n*≥ 0). The axiom states that deterministic external choice distributes over internal choice:

*a*

_{i}need not be all different, as an abbreviation for a deterministic one, via:

*a*

_{1}→

*t*

_{1}□ □

_{i = 2}

^{n}

*a*

_{i}

*t*

_{i}even when

*a*

_{1}is some

*a*

_{i}, for

*i*> 1. We can now write our final axiom:

*b*

_{1}→

*y*

_{1}) □ □

_{j}

*b*

_{j}

*y*

_{j}to be deterministic gives an equivalent axiom, as does restricting □

_{i}

*a*

_{i}

*x*

_{i}(in the presence of the others).

### Theorem 2.

*The finitary refusal sets algebra*\({\mathcal{R}}_{\mathit{df }}\)*is complete for equations between closed* CSP *(∣) terms.*

### Proof.

De Nicola’s normal form can be regarded as written in the signature of CSP(∣), and a straightforward induction proves that every CSP(∣) term can be reduced to such a normal form using the above axioms. But two such normal forms have the same denotation whether they are regarded as CSP ( □ ) or as CSP(∣) terms, and in the former case, by Lemma 4.8 of [10], they are identical.

### Theorem 3.

*The finitary refusal sets algebra*\({\mathcal{R}}_{\mathit{df }}\)*is the initial* CSP *(∣) algebra.*

### Proof.

Following the proof of Lemma 2 we see that every finitary refusal set is definable by a closed CSP(∣) term. With that, initiality follows from the above completeness theorem, as in the proof of Theorem 1.

*f* :

*A*→

*A*,

*h*

_{Rl} :

*T*

_{CSP(∣)}(

*∅*) →

*T*

_{CSP(∣)}(

*∅*) is defined homomorphically by:

*a*, but, surprisingly perhaps, one needs to assume that □ is available. For every

*a*∈

*A*one defines

*h*

_{a} :

*T*

_{CSP(∣)}(

*∅*) →

*T*

_{CSP(∣)}(

*∅*) homomorphically by:

### Proposition 2.

*One can define a* CSP *(∣)-algebra {Con} on T*_{CSP (∣)}*(∅) by:*

\({({\square }_{\vec{a}})}_{\mathit{Con}}({F}_{1},\ldots,{F}_{n}) = \left \{\begin{array}{ll} {F}_{j} \sqcap({F}_{j}\ ;\square \;{\square }_{i\neq j}{a}_{i}{F}_{i})&(\mbox{ if }a = {a}_{j}) \\ {\square }_{i}{a}_{i}{F}_{i} &(\mbox{ if }a\neq \mbox{ any}\;{a}_{i}) \end{array} \right.\)

The operator □ is, of course, no longer available as a constructor. However, it can alternatively be treated as a binary deconstructor. While its treatment as such is no more successful than our treatment of parallel operators, it is also no less successful. We define it simultaneously with (*n* + 1)-ary functions \({\square }^{{a}_{1}\ldots {a}_{n}}\) on *T*_{CSP(∣)}(*∅*), for *n* ≥ 0, where the *a*_{i} are all distinct. That we are defining infinitely many functions simultaneously arises from dealing with the infinitely many deterministic choice operators (there would be be infinitely many even if we considered them as parameterised on the *a*’s). However, we anticipate that this will cause no real difficulty, given that we have overcome the difficulty of dealing with binary deconstructors.

*a*

_{1}→

*t*

_{1}) □ □

_{i = 2}

^{n}

*a*

_{i}

*t*

_{i}is used

*n*times. It is clear that □ together with the functions

*n*+ 1)-ary functions \(\mid {\mid }^{{a}_{1}\ldots {a}_{n}}\) on

*T*

_{CSP(∣)}(

*∅*), for

*n*≥ 0, where the

*a*

_{i}are all distinct:

*left interleaving*operator ∣∣∣

^{l}and a

*right interleaving*operator ∣∣∣

^{r}so that:

*u*∣

^{l}

*v*is the set of interleavings of

*u*and

*v*which begin with a letter of

*u*, and

*u*∣

^{r}

*v*is defined analogously. It is interesting to note that:

^{r}.

## 15.6 Adding divergence

*failures/ divergences*model of [13], further elaborated in [29]. A characteristic property of this model is that divergence, i.e., an infinite sequence of internal actions, is modelled as

*Chaos*, a process that satisfies the equation:

*Chaos*no further process activity is discernible.

An alternative extension is the *stable failures* model proposed in [6], and also elaborated in [29]. This model equates processes that allow the same *observations*, where actions and deadlock are considered observable, but divergence does not give rise to any observations. A failure pair (*w*, *W*) now allowing *W* to be infinite records an observation in which *w* represents a sequence of actions being observed, and *W* represents the observation of deadlock under the assumption that the environment in which the observed process is running allows only the (inter)actions in the set *W*. Such an observation can be made if after engaging in the sequence of visible actions *w*, the observed process reaches a state in which no further internal actions are possible, nor any actions from the set *W*. Besides failure pairs, also traces are observable, and thus the observable behaviour of a process is given by a pair (*T*, *F*) where *T* is a set of traces and *F* is a set of failure pairs. Unlike the model \({\mathcal{R}\!}_{f}\) of Section 15.3, the traces are not determined by the failure pairs. In fact, in a process that can diverge in every state, the set of failure pairs is empty, yet the set of traces conveys important information.

In the remainder of this paper we add a constant *Ω* to the signature of CSP that is a zero for the semilattice generated by ⊓. This will greatly facilitate the forthcoming development. Intuitively, one may think of *Ω* as divergence in the stable failures model.

*Ω*and the single axiom:

*Ω*). We note two useful derived equations:

*process*is now given by a pair (

*T*,

*F*), where

*T*is a set of traces and

*F*is a set of failure pairs that satisfy the following conditions:

- 1.
ε ∈

*T* - 2.
*wa*∈*T*⇒*w*∈*T* - 3.
(

*w*,*W*) ∈*F*⇒*w*∈*T* - 4.
(

*w*,*W*) ∈*F*∧*V*⊆*W*⇒ (*w*,*V*) ∈*F* - 5.
(

*w*,*W*) ∈*F*∧ ∀*a*∈*V*.*wa*∉*T*⇒ (*w*,*W*∪*V*) ∈*F*(where V ⊆ A)

*P*are denoted

*T*

_{P}and

*F*

_{P}, respectively, and for

*w*∈

*T*

_{P}we define fut

_{P}(

*w*) : = {

*a*∈

*A*∣

*wa*∈

*T*

_{P}}. We can define the CSP operators on processes by setting

_{ℛ}is given as \(\mathrm{{op}}_{{\mathcal{R}\!}_{f}}\) was in Section 15.3, but without the restriction to finite sets

*W*in defining Stop

_{ℛ}. For the new process

*Ω*we set

*Ω*)-algebra,

*ℱ*.

A process *P* is called *finitary* if *T*_{P} is finite. The finitary processes evidently form a subalgebra of \(\mathcal{F}\); we call it \({\mathcal{F}\!\!\!}_{f}\).

### Lemma 3.

*Let P be a finitary process. Then, for every w ∈ T*_{P}*there is an n ≥ 0 and V*_{1}*,…,V*_{n}*⊆**fut*_{F}*(w) such that (w,W) ∈ F*_{P}*iff W ∩ V*_{i}*= ∅ for some i ∈ {1,…,n}.*

### Proof.

Closure conditions 4 and 5 above imply that (*w*, *W*) ∈ *F*_{P} if, and only if, (*w*, *W* ∩ fut_{P}(*w*)) ∈ *F*_{P}. Thus we only need to be concerned about pairs (*w*, *W*) with *W* ⊆ fut_{P}(*w*). Now, as fut_{P}(*w*) is finite, for any relevant (*w*, *W*) ∈ *F*, of which there are finitely many, we can take *V* to be fut_{P}(*w*) ∖ *W*, and we obtain finitely many such sets.

Note that it may happen that *n* = 0, in contrast with the case of Lemma 1.

### Lemma 4.

*All finitary processes are definable by closed* CSP *(□,Ω) terms.*

### Proof.

*P*be a finitary process. We proceed by induction on the length of the longest trace in

*T*

_{P}. By the previous lemma there are sets

*V*

_{1},

*…*,

*V*

_{n}, for some

*n*≥ 0, such that (ε,

*W*) ∈

*F*iff

*W*∩

*V*

_{i}=

*∅*for some

*i*∈ { 1,

*…*,

*n*}. Define

*T*

_{a}and

*F*

_{a}, for

*a*∈

*T*

_{P}, by:

*P*

_{a}: = (

*T*

_{a},

*F*

_{a}) is a finitary process, and that

*T*

_{a}is strictly shorter than the longest one in

*T*

_{P}, the proof concludes, employing the induction hypothesis.

### Proposition 3.

CSP *(□,Ω) is ground equationally complete with respect to both*\(\mathcal{F}\)*and*\({\mathcal{F}\!\!\!}_{f}\)*.*

### Proof.

*Ω*)-term of the form

*ℒ*is a finite non-empty saturated collection of finite sets of actions,

*K*is a finite set of actions, and each term

*t*

_{a}is in normal form. Every term is provably equal in CSP ( □,

*Ω*) to a term in normal form; the proof proceeds as for Proposition 1, but now also using the derived equations (15.14). Next, by Lemma 6 below, if two normal forms have the same denotation in \(\mathcal{F}\) then they are identical. So the result follows for \(\mathcal{F}\), and then for \({\mathcal{F}\!\!\!}_{f}\) too, as all closed terms denote finitary processes.

### Theorem 4.

*The algebra*\({\mathcal{F}\!\!\!}_{f}\)*of finitary processes is the initial* CSP *(□,Ω) algebra.*

### Proof.

Let the initial such algebra be I. There is a unique homomorphism \(h\! :\!\mathrm{ I} \rightarrow {\mathcal{F}\!\!\!}_{f}\). By Lemma 4, *h* is a surjection. By the previous proposition, \({\mathcal{F}\!\!\!}_{f}\) is complete for equations between closed terms, and so *h* is an injection. Hence *h* is an isomorphism, completing the proof.

As in Section 15.5, in order to deal with deconstructors, particularly hiding, we replace external choice by deterministic external choice. The availability of *Ω* permits useful additional such operators. The equational theory CSP( |, *Ω*) has as signature the binary operation symbol ⊓, and for any deterministic action sequence \(\vec{a}\), the *n*-ary operation symbols \({\square }_{\vec{a}}\) (as in Section 15.5), as well as the new *n*-ary operation symbols \({\square }_{\vec{a}}^{\Omega }\), for *n* ≥ 0, which denote a deterministic external choice with *Ω* as one of the summands. We adopt conventions for \({\square }_{\vec{a}}^{\Omega }\) analogous to those previously introduced for \({\square }_{\vec{a}}({t}_{1},\ldots,{t}_{n})\). We write \({\square }_{\vec{a}}^{\Omega }({t}_{1},\ldots,{t}_{n})\) as *Ω* □ □ _{i = 1}^{n}*a*_{i}*t*_{i}. We also write *Ω* □ (*c*_{1} → *t*_{1}) □ □ _{j = 2}^{n}*c*_{j}*t*_{j} for *Ω* □ □ _{j = 1}^{n}*c*_{j}*t*_{j}, so that the *c*_{j} (*j* = 1, *n*) must all be distinct.

*Ω*) are:

⊓,

*Ω*Is a semilattice with a zero here*Ω*is the 0-ary case of \({\square }_{\vec{a}}^{\Omega }\)Both deterministic external choice operators \({\square }_{\vec{a}}\) and \({\square }_{\vec{a}}^{\Omega }\) are commutative, as explained in Section 15.5

Both deterministic external choice operators distribute over internal choice, as explained in Section 15.5

_{a ∈ I}

*at*

_{a}or

*Ω*□ □

_{a ∈ I}

*at*

_{a}, over finite, possibly empty, sets of actions

*I*, assuming some standard ordering of pairs (

*a*,

*t*

_{a}) without repetitions. Next, using the analogous convention to (15.6) we can then also understand

*Ω*□ □

_{j = 1}

^{n}

*c*

_{j}

*t*

_{j}, and so also

*Ω*□ (

*c*

_{1}→

*t*

_{1}) □ □

_{j = 2}

^{n}

*c*

_{j}

*t*

_{j}, even when the

*c*

_{j}are not all distinct. With these conventions established, we can now state the final group of axioms. These are all variants of Axiom (15.7) of Section 15.5, allowing each of the two deterministic external choices to have an

*Ω*-summand:

*c*

_{k}=

*a*

_{k}and

*t′*

_{k}=

*t*

_{k}, for

*k*= 1,

*m*, and \({c}_{k} = {b}_{k-m}\), and \({t^{\prime\prime}}_{k} = {t^{\prime}}_{k-m}\), for \(k = m+1,m+n\); and \((\Omega \square {\square }_{i=1}^{m}{a}_{i}{t}_{i})\square ({\square }_{j=1}^{n}{b}_{j}{t}_{j})\) is understood analogously. In fact, the first three axioms of (15.18) are also derivable from (15.19), in the presence of the other axioms, and thus may be replaced by (15.19).

*Ω*)-algebra \({\mathcal{F}\!\!}_{d}\) as before, writing:

### Theorem 5.

*The algebra*\({\mathcal{F}\!\!}_{d}\)*is complete for equations between closed* CSP *(|,Ω) terms.*

### Theorem 6.

*The finitary subalgebra*\({\mathcal{F}\!\!}_{\mathit{df }}\)*of*\({\mathcal{F}\!\!}_{d}\)*is the initial* CSP *(|,Ω) algebra.*

*f*one simply adds the equation:

*a*∈

*A*one defines

*h*

_{a} :

*T*

_{CSP(∣, Ω)}(

*∅*) →

*T*

_{CSP(∣, Ω)}(

*∅*) homomorphically by:

## 15.7 Combining CSP and Functional Programming

To combine CSP with functional programming, specifically the computational λ-calculus, we use the monad *T*_{CSP( |, Ω)} for the denotational semantics. As remarked above, CSP processes then become terms of type empty. However, as the** constructors are polymorphic, it is natural to go further and look for polymorphic versions of the deconstructors. We therefore add polymorphic constructs to λ_{c} as follows:

**Constructors**

**Unary Deconstructors**

*f*, and any

*a*∈

*A*. (One should really restrict the allowable relabelling functions in order to keep the syntax finitary.)

**Binary Deconstructors**

*a*→ − and

*Ω*with the aid of the □ deconstructor.

*T*

_{CSP( |, Ω)}, which we know exists by the general considerations of Section 15.2. These general considerations also yield a semantics for the constructors. For example, for every set

*X*we have the map:

*X*= [[σ]] to interpret terms

*M*⊓

*N* : σ.

*f*we need a function:

_{X} :

*X* →

*T*

_{CSP( |, Ω)}(

*X*), equipping

*T*

_{CSP( |, Ω)}(

*X*) with the algebra structure

*x*,

*y*∈

*T*

_{CSP( |, Ω)}(

*X*),

\({\left ({\square }_{\vec{a}}\right )}_{\mathcal{A}}\left ({x}_{1},\ldots,{x}_{n}\right ) ={ \left ({\square }_{f(\vec{a})}\right )}_{X}({x}_{1},\ldots,{x}_{n})\)

and

\({\left ({\square }_{a}^{\Omega }\right )}_{\mathcal{A}}({x}_{1},\ldots,{x}_{n}) ={ \left ({\square }_{f(a)}^{\Omega }\right )}_{X}\left ({x}_{1},\ldots,{x}_{n}\right )\)

*a*can be treated analogously, but now following the treatment in the case of \({\mathcal{F}\!\!}_{\mathit{df }}\), and defining \(\mathcal{A}\) by:

*x*,

*y*∈

*T*

_{CSP( |, Ω)}(

*X*)0

\({({\square }_{a})}_{\mathcal{A}}({x}_{1},\ldots,{x}_{n}) = \left \{\begin{array}{ll} {x}_{j} \sqcap(\Omega \square {\square }_{i\neq j}{a}_{i}{x}_{i})&(\mbox{ if }a = {a}_{j},\,\mbox{ where}\,1 \leq j \leq n) \\ {\square }_{i=1}^{n}{a}_{i}{x}_{i} &(\mbox{ if }a\neq \mbox{ any}\;{a}_{i})\end{array} \right.\)

and

\({({\square }_{a}^{\Omega })}_{\mathcal{A}}({x}_{1},\ldots,{x}_{n}) = \left \{\begin{array}{ll} {x}_{j} \sqcap(\Omega \square {\square }_{i\neq j}{a}_{i}{x}_{i})&(\mbox{ if }a = {a}_{j},\,\mbox{ where}\,1 \leq j \leq n) \\ \Omega \square {\square }_{i=1}^{n}{a}_{i}{x}_{i} &(\mbox{ if }a\neq \mbox{ any}\;{a}_{i})\end{array} \right.\)

We here again make use of the deterministic choice operator made available by the presence of *Ω*.

However, we cannot, of course, carry this on to binary deconstructors as we have no general algebraic treatment of them. We proceed instead by giving a concrete definition of them (and the other constructors and deconstructors). That is, we give an explicit description of the free CSP( |, *Ω*)-algebra on a set *X* and define our operators in terms of that representation.

An *X-trace* is a pair (*w*, *x*), where *w* ∈ *A*^{∗} and *x* ∈ *X*; it is generally more suggestive to write (*w*, *x*) as *wx*. For any relabelling function *f*, we set *f*(*w*) = *f*(*w*)*x*, and, for any *a* ∈ *A*, we set *wx* ∖ *a* = (*w* ∖ *a*)*x*. An *X-process* is a pair (*T*, *F*) with *T* a set of traces as well as *X*-traces, and *F* a set of failure pairs, satisfying the same five conditions as in Section 15.6, together with:

2^{′}. *wx* ∈ *T* ⇒ *w* ∈ *T* (for *x* ∈ *X*)

*X*-processes exactly as before, except that the two parallel operators now have more general types:

_{P}(

*w*) : = {

*a*∈

*A*∣

*wa*∈

*T*

_{P}}, as before.

*X*-processes. The

*X*-processes also form the carrier of a CSP( |,

*Ω*)-algebra \({\mathcal{F}\!\!}_{d}(X)\), with the operators defined as follows:

*X*-processes are those with a finite set of traces and

*X*-traces; they form the carrier of a CSP( |,

*Ω*)-algebra \({\mathcal{F}\!\!}_{\mathit{df }}(X)\).

*Ω*)-algebra over

*X*. As is well known, the free algebra of a theory Th over a set

*X*is the same as the initial algebra of the theory Th

^{+}obtained by extending Th with constants \(\underline{x}\) for each

*x*∈

*X*but without changing the axioms. The unit map η :

*X*→

*T*

_{Th}(

*X*) sends

*x*∈

*X*to the denotation of \(\underline{x}\) in the initial algebra. We therefore show that \({\mathcal{F}\!\!}_{\mathit{df }}(X)\), extended to a CSP( |, )

^{+}-algebra by taking

*Ω*)

^{+}-algebra. We begin by looking at definability.

### Lemma 5.

*The finitary X-processes are those definable by closed* CSP *(|,Ω)*^{+}*terms.*

### Proof.

The proof goes just as the one for Lemma 4, using that Lemma 3 applies just as well to finitary *X*-processes, but this time we have\(P = {\sqcap }_{i}{\square }_{a\in {V }_{i}}a \rightarrow{P}_{a}\ \sqcap \ \left (\Omega \square {\square }_{a\in {T}_{P}}a \rightarrow{P}_{a}\right )\ \sqcap \ {\sqcap }_{x\in {T}_{P}}\underline{x}\)

*Ω*)

^{+}-term

*t*is in

*normal form*if it is has one of the following two forms:

*ℒ*is a finite non-empty saturated collection of finite sets of actions,

*J*⊆

_{fin}

*X*,

*K*⊆

_{fin}

*A*, and each term

*t*

_{a}is in normal form.

### Lemma 6.

*Two normal forms are identical if they have the same denotation in*\({\mathcal{F}\!\!}_{\mathit{df }}(X)\)*.*

### Proof.

*T*,

*F*). As (ε,

*∅*) ∈

*F*iff

*F*is the denotation of a normal form of the first form (rather than the second), both normal forms must be of the same form. Thus, there are two cases to consider, the first of which concerns two forms:

*J*=

*J′*. Next, if

*a*∈ ⋃

*ℒ*then

*a*∈

*T*and so \(a \in \bigcup\nolimits \mathcal{L}\); we therefore have that \(\bigcup\nolimits \mathcal{L}\subseteq \bigcup\nolimits \mathcal{L^{\prime}}\). Now, if

*L*∈

*ℒ*, then \((\epsilon,(\bigcup\nolimits \mathcal{L^{\prime}})\setminus L) \in F\); so for some

*L′*∈

*ℒ*we have \(L \cap((\bigcup\nolimits \mathcal{L^{\prime}})\setminus L) = \emptyset \), and so

*L′*⊆

*L*. As \(\mathcal{L}\) is saturated, it follows by the previous remark that

*L*∈

*ℒ′*. So we have the inclusion \(\mathcal{L}\subseteq \mathcal{L^{\prime}}\) and then, arguing symmetrically, equality.

Finally, the denotations of *t*_{a} and *t′*_{a}, for \(a \in \bigcup\nolimits \mathcal{L} = \bigcup\nolimits \mathcal{L}\) are the same, as they are determined by *T* and *F*, being {*w*∣*aw* ∈ *T*} and {(*w*, *W*)∣(*aw*, *W*) ∈ *F*}, and the argument concludes, using the inductive hypothesis.

*J*=

*J′*,

*K*=

*K′*, and

*t*

_{a}=

*t*

_{a}for

*a*∈

*K*.

### Lemma 7.

CSP *(|,Ω)*^{+}*is ground complete with respect to*\({\mathcal{F}\!\!}_{\mathit{df }}(X)\)*.*

### Proof.

As before, a straightforward induction shows that every term has a normal form, and then completeness follows by Lemma 6.

### Theorem 7.

*The algebra*\({\mathcal{F}\!\!}_{\mathit{df }}(X)\)*is the free* CSP *(|,Ω)-algebra over X.*

### Proof.

It follows from Lemmas 5 and 7 that \({{\mathcal{F}\!\!}_{\mathit{df }}(X)}^{+}\) is the initial CSP( |, *Ω*)^{+}-algebra.

As with any finitary equational theory, CSP( |, *Ω*) is equationally complete with respect to \({\mathcal{F}\!\!}_{\mathit{df }}(X)\) when *X* is infinite. It is not difficult to go a little further and show that this also holds when *X* is only required to be non-empty, and, even, if *A* is infinite, when it is empty.

Now that we have an explicit representation of the free CSP( |, *Ω*)-monad in terms of *X*-processes, we indicate how to use it to give the semantics of the computational λ-calculus. First we need the structure of the monad. As we know from the above, the unit η_{X} : *X* → *T*_{CSP( |, Ω)}(*X*) is the map *x*↦({*x*}, *∅*). Next, we need the homomorphic extension \({g}^{\dag }\! :\! {\mathcal{F}\!\!}_{\mathit{df }}(X) \rightarrow {\mathcal{F}\!\!}_{\mathit{df }}(Y )\) of a given map \(g\! :\! X \rightarrow {\mathcal{F}\!\!}_{\mathit{df }}(Y )\), i.e., the unique such homomorphism making the following diagram commute:

*X*-processes. We have also already given homomorphic treatments of the unary deconstructors. We finally give treatments of the binary deconstructors as unique solutions to equations, along similar lines to their treatment in the case of \({\mathcal{F}\!\!}_{\mathit{df }}\). Observe that:

_{X}, □

_{X}

^{Ω, a}

_{1}

*…a*

_{n}and □

_{X}

^{a}

_{1}

*…a*

_{n}, the latter defined as in Eq. 15.9 are the unique functions which satisfy the evident analogues of Eq. 15.8 together with, making another use of the form of external choice made available by

*Ω*:

*a*

_{i}∈

*A*are all different, and

*x*∈

*X*, by the analogues of Eq. 15.10 above, together with:

_{X, Y}.

_{X, Y}

^{l}, ∣∣∣

_{X, Y}

^{r}are components of the unique solutions to the analogues of Eq. 15.11 above, together with:

^{r}and ∣∣∣

^{r, y}.

*Ω*)-algebras obey. Note that some adjustments need to be made due to varying types. For example, ∣∣ is commutative, which here means that the following equation holds:

*X*×

*Y*→

*Y*×

*X*is the commutativity map (

*x*,

*y*)↦(

*y*,

*x*).

### 15.7.1 Termination

As remarked in the introduction, termination and sequencing are available in a standard way for terms of type unit. Syntactically, we regard skip as an abbreviation for ∗ and *M*; *N* as one for (λ*x* : unit. *N*)(*M*) where *x* does not occur free in *N*; semantically, we have a corresponding element of, and binary operator over, the free CSP( |, *Ω*)-algebra on the one-point set.

The deconstructors are defined as above except that in the case of the concurrency operators one has to adjust \(\mid {\mid }_{ \{\surd\},\{\surd\}}\) and \(\mid \mid {\mid }_{ \{\surd\},\{\surd\}}\) so that they remain within the world of the \(\{\surd\}\)-processes; this can be done by postcomposing them with the evident bijection between \(\{\surd\}\times \{\surd\}\)-processes and \(\{\surd\}\)-processes, and all this restricts to the finitary processes. Alternatively one can directly consider these adjusted operators as deconstructors over the (finitary) \(\{\surd\}\)-processes.

*T*,

*F*) = (

*T*,

*F′*) where

*F′*to the set:

## 15.8 Discussion

We have shown the possibility of a principled combination of CSP and functional programming from the viewpoint of the algebraic theory of effects. The main missing ingredient is an algebraic treatment of binary deconstructors, although we were able to partially circumvent that by giving explicit definitions of them. Also missing are a logic for proving properties of these deconstructors, an operational semantics, and a treatment that includes recursion.

As regards a logic, it may prove possible to adapt the logical ideas of [24, 25] to handle binary deconstructors; the main proof principle would then be that of *computation induction*, that if a proposition holds for all “values” (i.e., elements of a given set *X*) and if it holds for the applications of each constructor to any given “computations” (i.e., elements of *T*(*X*)) for which it is assumed to hold, then it holds for all computations. We do not anticipate any difficulty in giving an operational semantics for the above combination of the computational λ-calculus and CSP and proving an adequacy theorem.

*t*≤

*u*, for terms

*t*,

*u*in a given signature

*Σ*); inequational theories can include equations, regarding an equation as two evident inequations. There is a natural inequational logic for deducing consequences of the axioms: one simply drops symmetry from the logic for equations [7]. Then

*Σ*-algebras and Th-algebras are taken in the category of ω-cpos and continuous functions, a free algebra monad always exists, just as in the case of sets, and the logic is complete for the class of such algebras. One includes a divergence constant

*Ω*in the signature and the axiom

The three classical powerdomains: convex (aka Plotkin), lower (aka Hoare) and upper (aka Smyth) provide a useful illustration of these ideas [12, 14]. One takes as signature a binary operation symbol ⊓, to retain notational consistency with the present paper (a more neutral symbol, such as ∪, is normally used instead), and the constant *Ω*; one takes the theory to be that ⊓is a semilattice (meaning, as before, that associativity, commutativity and idempotence hold) and that, as given above, *Ω* is the least element with respect to the ordering ≤. This gives an algebraic account of the convex powerdomain.

If one adds that *Ω* is the zero of the semilattice (which is equivalent, in the present context, to the inequation *x* ≤ *x* ⊓*y*) one obtains instead an algebraic account of the lower powerdomain. One then further has the notationally counterintuitive facts that *x* ≤ *y* is equivalent to *y* ⊑ *x*, with ⊑ defined as in Section 15.3, and that *x* ⊓*y* is the supremum of *x* and *y* with respect to ≤ ; in models, ≤ typically corresponds to subset. It would be more natural in this case to use the dual order to ⊑ and to write ⊔ instead of ⊓, when we would be dealing with a join-semilattice with a least element whose order coincides with ≤.

If one adds instead that *x* ⊓*y* ≤ *x*, one obtains an algebraic account of the upper powerdomain. One now has that *x* ≤ *y* is equivalent in this context to *x* ⊑ *y*, that *x* ⊓*y* is the greatest lower bound of *x* and *y*, and that *x* ⊓*Ω* = *Ω* (but this latter fact is not equivalent in inequational logic to *x* ⊓*y* ≤ *x*); in models, ≤ typically corresponds to superset. The notations ⊓and ⊑ are therefore more intuitive in the upper case, and there one has a meet-semilattice with a least element whose order coincides with ≤.

It will be clear from these considerations that the stable failures model fits into the pattern of the lower powerdomain and that the failures/divergences model fits into the pattern of the upper powerdomain. In the case of the stable failures model it is natural, in the light of the above considerations, to take Th to be CSP( |, *Ω*) together with the axiom *Ω* ≤ *x*. The *X*-processes with countably many traces presumably form the free algebra over *X*, considered as a discrete ω-cpo; one should also characterise more general cases than discrete ω-cpos.

One should also investigate whether a fragment of the failures/divergences model forms the initial model of an appropriate theory, and look at the free models of such a theory. The theory might well be found by analogy with our work on the stable failures model, substituting (15.12) for (15.13) and, perhaps, using the mixed-choice constructor, defined below, to overcome any difficulties with the deconstructors. One would expect the initial model to contain only finitely-generable processes, meaning those which, at any trace, either branch finitely or diverge (and see the discussion in [29]).

Our initial division of our selection of CSP operators into constructors and deconstructors was natural, although it turned out that a somewhat different division, with “restricted” constructors, resulted in what seemed to be a better analysis (we were not able to rule out the possibility that there are alternative, indirect, definitions of the deconstructors with the original choice of constructors). One of these restricted constructors was a deterministic choice operator making use of the divergence constant *Ω*. There should surely, however, also be a development without divergence that allows the interpretation of the combination of CSP and functional programming.

*mixed-choice*operator of the form:

_{i}is either an action or τ, would lead to a satisfactory theory. This new operator is given by the equation:

_{i}∖

*a*). Note that in the stable failures model we have the equation:

*Ω*played so central a rôle there.

In a different direction, one might also ask whether there is some problem if we alternatively take an extended set of operators as constructors. For example, why not add relabelling with its equations to the axioms? As the axioms inductively determine relabelling on the finitary refusal sets model, that would still be the initial algebra, and the same holds if we add any of the other operators we have taken as deconstructors.

*X*-refusal sets would not longer be the free algebra, as there would be extra elements, such as

*f*(

*x*) for

*x*∈

*X*, where

*f*is a relabelling function. We would also get some undesired equations holding between terms of the computational λ-calculus. For any

*n*-ary constructor op and evaluation context

*E*[ − ], one has in the monadic semantics:

*E*[

*f*(

*M*)] =

*f*(

*E*[

*M*]) if one took relabelling as a constructor, and, as another example, one would have

*E*[

*M*∣∣

*N*] =

*E*[

*M*]∣∣

*E*[

*N*] if one took the concurrency operator as a constructor.

It will be clear to the reader that, in principle, one can investigate other process calculi and their combination with functional programming in a similar way. For example, for Milner’s CCS [17] one could take action prefix (with names, conames and τ) together with NIL and the sum operator as constructors, and as axioms that we have a semilattice with a zero, for strong bisimulation, together with the usual τ-laws, if we additionally wish to consider weak bisimulation. The deconstructors would be renaming, hiding, and parallel, and all should have suitable polymorphic versions in the functional programming context. Other process calculi such as the π-calculus [30, 33], or even the stochastic π-calculus [26, 16], might be dealt with similarly. In much the same way, one could combine parallelism with a global store with functional programming, following the algebraic account of the resumptions monad [14, 1] where the constructors are the two standard ones for global store [22], a nondeterministic choice operation, and a unary “suspension” operation.

A well-known feature of the monadic approach [14] is that it is often possible to combine different effects in a modular way. For example, the global side-effects monad is (*S* × − )^{S} where *S* is a suitable set of states. A common combination of it with another monad *T* is the monad *T*(*S* × − )^{S}. So, taking *T* = *T*_{CSP(∣)}, for example, we get a combination of CSP with global side-effects.

As another example, given a monoid *M*, one has the *M*-action monad *M* × − which supports a unary *M*-action effect constructor *m*. −, parameterised by elements *m* of the monoid. One might use this monad to model the passage of time, taking *M* to be, for example, the monoid of the natural numbers IN under addition. A suitable combination of this monad with ones for CSP may yield helpful analyses of timed CSP [27, 20], with *Wai* *n*; − given by the IN-action effect constructor. We therefore have a very rich space of possible combinations of process calculi, functional programming and other effects, and we hope that some of these prove useful.

Finally, we note that there is no general account of how the equations used in the algebraic theory of effects arise. In such cases as global state, nondeterminism or probability, there are natural axioms and monads already available, and it is encouraging that the two are equivalent [22, 14]. One could investigate using operational methods and behavioural equivalences to determine the equations, and it would be interesting to do so. Another approach is the use of “test algebras” [32, 15]. In the case of process calculi one naturally uses operational methods; however, the resulting axioms may not be very modular, or very natural mathematically, and, all in all, in this respect the situation is not satisfactory.

## 15.9 Appendix: The Computationalλ-Calculus

_{c}-calculus [18, 19]. It has types given by:

*T*σ may be defined to be unit → σ. The terms of the λ

_{c}-calculus are given by:

*g*ranges over given unary function symbols of given types σ → τ, such as 0 : unit → nat or succ : nat → nat, if we want the natural numbers, or op :

*T*(σ) ×

*…*×

*T*(σ) →

*T*(σ) for some operation symbol from a theory for which

*T*is the free algebra monad. There are standard notions of free and bound variables and of closed terms and substitution; there are also standard typing rules for judgements

*Γ*⊢

*M* : σ, that the term

*M*has type σ in the context

*Γ*(contexts have the form

*Γ*=

*x*

_{1}: σ

_{1},

*…*,

*x*

_{n}: σ

_{n}), including:

A λ_{c}-model (on the category of sets Moggi worked more generally) consists of a monad *T*, together with enough information to interpret basic types and the given function symbols. So there is a given set [[*b*]] to interpret each basic type *b*, and then every type σ receives an interpretation as a set [[σ]]; for example [[empty ]] = *∅*. There is also given a map [[σ]] → *T*([[τ]]) to interpret every given unary function symbol *g* : σ → τ. A term *Γ* ⊢ *M* : σ of type σ in context *Γ* is modelled by a map [[*M*]] : [[*Γ*]] → *T*[[σ]] (where [[*x*_{1} : σ_{1}, *…*, *x*_{n} : σ_{n}]] = [[σ_{1}]] ×*…* ×[[σ_{n}]]). For example, if *Γ* ⊢ in*M* : σ then [[in*M*]] = 0_{[[σ]]}*o*[[*M*]] (where, for any set *X*,0_{X} is the unique map from *∅* to *X*).

*E*[

*M*] for the term obtained by replacing the ‘hole’ [ − ] in an evaluation term

*E*by a term

*M*. The computational thought behind evaluation contexts is that in a program of the form

*E*[

*M*], the first computational step arises within

*M*.

### References

- 1.Abadi, M., Plotkin, G.D.: A model of cooperative threads. In: Shao, Z., Pierce, B.C. (eds.), Proc. POPL 2009. ACM Press, pp. 29 40 (2009)Google Scholar
- 2.Abramsky, S., Gabbay, D.M., Maibaum, T.S.E. (eds.), Handbook of Logic in Computer Science (Vol. 1), Background: Mathematical Structures, Oxford University Press (1995)MATHGoogle Scholar
- 3.Benton, N., Hughes, J., Moggi, E.: Monads and effects. Proc. APPSEM 2000, LNCS
**2395**, pp. 42 122, Springer (2002)Google Scholar - 4.Bergstra, J.A., Klop, J.W.: Algebra of communicating processes with abstraction. Theor. Comput. Sci.
**37**, pp. 77 121 (1985)CrossRefMATHMathSciNetGoogle Scholar - 5.Bergstra, J.A., Klop, J.W.: Algebra of communicating processes. In: de Bakker, J.W., Hazewinkel, M., Lenstra, J.K. (eds.), Proc. of the CWI Symp. Math. and Comp. Sci. pp. 89 138, North-Holland (1986)Google Scholar
- 6.Bergstra, J.A., Klop, J.W., Olderog, E.-R.: Failures without chaos: a new process semantics for fair abstraction. In: Wirsing, M. (ed.), Proc. of the 3
^{rd}IFIP WG 2.2 working conference on Formal Description of Programming Concepts. pp. 77 103, North-Holland (1987)Google Scholar - 7.Bloom, S.L.: Varieties of ordered algebras. J. Comput. Syst. Sci.,
**13**(2):200 212 (1976)CrossRefMATHGoogle Scholar - 8.Borceux, F.: Handbook of Categorical Algebra 2, Encyclopedia of Mathematics and Its Applications
**51**. Cambridge University Press (1994)Google Scholar - 9.Brookes, S.D., Hoare, C.A.R., Roscoe, A.W.: A theory of communicating sequential processes. J. ACM
**31**(3):560 599 (1984)CrossRefMATHMathSciNetGoogle Scholar - 0.De Nicola, R.: Two complete axiom systems for a theory of communicating sequential processes. Inform. Control
**64**, pp. 136 172 (1985)CrossRefMATHGoogle Scholar - 1.Ebrahimi-Fard, K., Guo, L.: Rota-Baxter algebras and dendriform algebras. J. Pure Appl. Algebra
**212**(2):320 33 (2008)CrossRefMATHMathSciNetGoogle Scholar - 2.Gierz, G., Hofmann, K.H., Keimel, K., Lawson, J.D., Mislove, M., Scott, D.S.: Continuous Lattices and Domains, Encyclopedia of Mathematics and its Applications
**93**. Cambridge University Press (2003)Google Scholar - 3.Hoare, C.A.R.: Communicating Sequential Processes. Prentice-Hall (1985)Google Scholar
- 4.Hyland, J.M.E., Plotkin, G.D., Power, A.J.: Combining effects: sum and tensor. In: Artemov, S., Mislove, M. (eds.), Clifford Lectures and the Mathematical Foundations of Programming Semantics. Theor. Comput. Sci.
**357**(1 3):70 99 (2006)Google Scholar - 5.Keimel, K., Plotkin, G.D.: Predicate transformers for extended probability and non-determinism. Math. Struct. Comput. Sci.
**19**(3):501 539. Cambridge University Press (2009)Google Scholar - 6.Klin, B., Sassone, V.: Structural operational semantics for stochastic process calculi. In: Amadio, R.M. (ed.), Proc. 11th. FoSSaCS. LNCS
**4962**, pp. 428 442, Springer (2008)Google Scholar - 7.Milner, A.J.R.G.: A Calculus of Communicating Systems. Springer (1980)Google Scholar
- 8.Moggi, E.: Computational lambda-calculus and monads. Proc. 3rd. LICS, pp. 14 23, IEEE Press (1989)Google Scholar
- 9.Moggi, E.: Notions of computation and monads. Inf. Comp.
**93**(1):55 92 (1991)CrossRefMATHMathSciNetGoogle Scholar - 0.Ouaknine, J., Schneider, S.: Timed CSP: a retrospective, Proceedings of the Workshop “Essays on Algebraic Process Calculi” (APC 25), Electr. Notes Theor. Comput. Sci.,
**162**, pp. 273 276 (2006)CrossRefGoogle Scholar - 1.Plotkin, G.D.: Some varieties of equational logic. Essays Dedicated to Joseph A. Goguen. In: Futatsugi, K., Jouannaud, J.-P., Meseguer, J. (eds.), LNCS
**4060**, pp. 150 156, Springer (2006)Google Scholar - 2.Plotkin, G.D., Power, A.J.: Notions of computation determine monads, Proc. 5th. FoSSaCS. LNCS
**2303**, pp. 342 356, Springer (2002)Google Scholar - 3.Plotkin, G.D., Power, A.J.: Computational effects and operations: an overview. In: Escardó, M., Jung, A. (eds.), Proc. Workshop on Domains VI. Electr. Notes Theor. Comput. Sci.
**73**, pp. 149 163, Elsevier (2004)Google Scholar - 4.Plotkin, G.D., Pretnar, M.: A logic for algebraic effects. Proc. 23rd. LICS, pp. 118 129, IEEE Press (2008)Google Scholar
- 5.Plotkin, G.D., Pretnar, M.: Handlers of algebraic effects. Proc. 18th. ESOP, pp. 80 94 (2009)Google Scholar
- 6.Priami, C.: Stochastic pi-calculus. Comput. J.
**38**(7):578 589 (1995)CrossRefGoogle Scholar - 7.Reed, G.M., Roscoe, A.W.: The timed failures-stability model for CSP. Theor. Comput. Sci.
**211**(1 2):85 127 (1999)CrossRefMATHMathSciNetGoogle Scholar - 8.Roscoe, A.W.: Model-checking CSP. In: Roscoe, A.W. (ed.), A Classical Mind: Essays in Honour of Hoare, C.A.R., pp. 353 337, Prentice-Hall (1994)Google Scholar
- 9.Roscoe, A.W.: The Theory and Practice of Concurrency. Prentice Hall (1998)Google Scholar
- 0.Sangiorgi, D., Walker, D.: The π-Calculus: A Theory of Mobile Processes. Cambridge University Press (2003)Google Scholar
- 1.Scattergood, B.: The Semantics and Implementation of Machine-Readable CSP. D.Phil Thesis, Oxford University (1998)Google Scholar
- 2.Schröder, M., Simpson, A.: Probabilistic observations and valuations (extended abstract). Electr. Notes Theor. Comput. Sci.
**155**, pp. 605 615 (2006)CrossRefGoogle Scholar - 3.Stark, I.: Free-algebra models for the pi-calculus. Theor. Comput. Sci.
**390**(2 3):248 270 (2008)CrossRefMATHGoogle Scholar