crdt-1.0: Conflict-free replicated data types

Safe HaskellNone
LanguageHaskell2010

CRDT.Cm

Synopsis

Documentation

class (Observe payload, Eq (Observed payload), PartialOrd update) => CmRDT payload op update | payload -> op, op -> update, update -> payload 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.

Minimal complete definition

updateAtSource, updateDownstream

Methods

updateAtSourcePre :: op -> payload -> Bool Source #

Precondition for updateAtSource. Calculates if the operation is applicable to the current state.

updateAtSource :: Clock m => op -> m update 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 :: update -> payload -> payload Source #

Apply an update to the payload. An invalid update must be ignored.

concurrent :: PartialOrd a => a -> a -> Bool Source #

Not comparable, i. e. ¬(a ≤ b) ∧ ¬(b ≤ a).