crdt-6.0: Conflict-free replicated data types

Safe HaskellNone
LanguageHaskell2010

CRDT.Cm

Synopsis

Documentation

class CausalOrd a where Source #

Partial order for causal semantics. Values of some type may be ordered and causally-ordered different ways.

Minimal complete definition

precedes

Methods

precedes :: a -> a -> Bool Source #

x precedes y means that x must go before y and y can not go before x.

Instances

Eq a => CausalOrd (TwoPSet a) Source # 

Methods

precedes :: TwoPSet a -> TwoPSet a -> Bool Source #

Eq a => CausalOrd (GSet a) Source # 

Methods

precedes :: GSet a -> GSet a -> Bool Source #

CausalOrd (Counter a) Source #

Empty order, allowing arbitrary reordering

Methods

precedes :: Counter a -> Counter a -> Bool Source #

CausalOrd (LWW a) Source # 

Methods

precedes :: LWW a -> LWW a -> Bool Source #

class (CausalOrd op, Eq (Payload op)) => CmRDT op 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 intent.

Payload
Internal state of a replica.
Intent
User's request to update.
Operation (Op)
Operation to be applied to other replicas.

For many types operation and intent 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.

∀ op1 op2 .
concurrent op1 op2 ==> apply op1 . apply op2 == apply op2 . apply op1

Idempotency doesn't need to hold.

Minimal complete definition

apply

Associated Types

type Intent op Source #

type Payload op Source #

Methods

makeOp :: Clock m => Intent op -> Payload op -> Maybe (m op) Source #

Generate an update to the local and remote replicas.

Returns Nothing if the intended operation is not applicable.

makeOp :: (Intent op ~ op, Applicative m) => Intent op -> Payload op -> Maybe (m op) Source #

Generate an update to the local and remote replicas.

Returns Nothing if the intended operation is not applicable.

apply :: op -> Payload op -> Payload op Source #

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

TODO(Syrovetsky, 2017-12-05) There is no downstream precondition yet. We must make a test for it first.

Instances

Ord a => CmRDT (TwoPSet a) Source # 

Associated Types

type Intent (TwoPSet a) :: * Source #

type Payload (TwoPSet a) :: * Source #

Methods

makeOp :: Clock m => Intent (TwoPSet a) -> Payload (TwoPSet a) -> Maybe (m (TwoPSet a)) Source #

apply :: TwoPSet a -> Payload (TwoPSet a) -> Payload (TwoPSet a) Source #

Ord a => CmRDT (GSet a) Source # 

Associated Types

type Intent (GSet a) :: * Source #

type Payload (GSet a) :: * Source #

Methods

makeOp :: Clock m => Intent (GSet a) -> Payload (GSet a) -> Maybe (m (GSet a)) Source #

apply :: GSet a -> Payload (GSet a) -> Payload (GSet a) Source #

(Num a, Eq a) => CmRDT (Counter a) Source # 

Associated Types

type Intent (Counter a) :: * Source #

type Payload (Counter a) :: * Source #

Methods

makeOp :: Clock m => Intent (Counter a) -> Payload (Counter a) -> Maybe (m (Counter a)) Source #

apply :: Counter a -> Payload (Counter a) -> Payload (Counter a) Source #

Eq a => CmRDT (LWW a) Source # 

Associated Types

type Intent (LWW a) :: * Source #

type Payload (LWW a) :: * Source #

Methods

makeOp :: Clock m => Intent (LWW a) -> Payload (LWW a) -> Maybe (m (LWW a)) Source #

apply :: LWW a -> Payload (LWW a) -> Payload (LWW a) Source #

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

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