Interface EffectTrait<Effect>

Type Parameters:
Effect - The type on which this object gives an effect algebra.

public interface EffectTrait<Effect>
A trait for performing effect-algebraic operations on a type.

We define an effect type to be a type whose values can be combined sequentially or concurrently, and which has a known value representing the absence of an effect. An implementation of EffectTrait<P> provides these operations for a type P, even if the definition of P itself cannot be changed. We will often refer to an implementation of EffectTrait<P> as "an effect algebra on P".

A useful graphical notation is to write x | y for trait.concurrently(x, y) (when trait is fixed), and x; y for trait.sequentially(x, y). Nested calls to these methods can then be understood as expressions over these algebraic operators.

Implementors are required to obey the following contract, up to observable behavior. This contract captures the common-sense behavior expected of effects that occur over time.

  • sequentially is associative: (x; y); z == x; (y; z)
  • concurrently is associative: (x | y) | z == x | (y | z)
  • concurrently is commutative: x | y == y | x
  • empty is the identity for sequential composition: empty(); x == x == x; empty()
  • empty is the identity for concurrent composition: empty() | x == x == x | empty()