Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Documentation
class CausalOrd a where Source #
Partial order for causal semantics. Values of some type may be ordered and causally-ordered different ways.
class (CausalOrd u, Eq (View u)) => CmRDT u where Source #
Operation-based, or commutative (Cm) replicated data type.
Implementation
In Haskell, a CmRDT implementation consists of 3 types —
a payload, an operation (op
) and an update.
- Payload
- Internal state of a replica.
- Operation
- User's request to update.
- Update
- Operation to be applied to other replicas.
For many types operation and update may be the same.
But for LWW
, for instance, this rule doesn't hold:
user can request only value, and type attaches a timestamp to it.
Additional constraint — commutativity law
Concurrent updates are observed equally.
∀ up1 up2 s .concurrent
up1 up2 ==>observe
(updateDownstream
up1 .updateDownstream
up2 $ s) ==observe
(updateDownstream
up2 .updateDownstream
up1 $ s)
Idempotency doesn't need to hold.
updateAtSourcePre :: Op u -> Payload u -> Bool Source #
Precondition for updateAtSource
.
Calculates if the operation is applicable to the current state.
updateAtSource :: Clock m => Op u -> m u Source #
Generate an update to the local and remote replicas.
Doesn't have sense if updateAtSourcePre
is false.
May or may not use clock.
updateAtSource :: (Clock m, Op u ~ u) => Op u -> m u Source #
Generate an update to the local and remote replicas.
Doesn't have sense if updateAtSourcePre
is false.
May or may not use clock.
updateDownstream :: u -> Payload u -> Payload u Source #
Apply an update to the payload. An invalid update must be ignored.
view :: Payload u -> View u Source #
Extract user-visible value from payload
view :: Payload u ~ View u => Payload u -> View u Source #
Extract user-visible value from payload
concurrent :: CausalOrd a => a -> a -> Bool Source #
Not comparable, i. e. ¬(a ≤ b) ∧ ¬(b ≤ a).