packages feed

crdt 3.0 → 4.0

raw patch · 7 files changed

+18/−19 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- CRDT.Cm: affects :: CausalOrd a => a -> a -> Bool
+ CRDT.Cm: precedes :: CausalOrd a => a -> a -> Bool

Files

crdt.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           crdt-version:        3.0+version:        4.0 synopsis:       Conflict-free replicated data types description:    Definitions of CmRDT and CvRDT. Implementations for some classic CRDTs. category:       Distributed Systems
lib/CRDT/Cm.hs view
@@ -13,12 +13,12 @@ -- | Partial order for causal semantics. -- Values of some type may be ordered and causally-ordered different ways. class CausalOrd a where-    -- | @x `affects` y@ means that+    -- | @x `precedes` y@ means that     -- @x@ must go before @y@ and @y@ can not go before @x@.-    affects :: a -> a -> Bool+    precedes :: a -> a -> Bool  comparable :: CausalOrd a => a -> a -> Bool-comparable a b = a `affects` b || b `affects` a+comparable a b = a `precedes` b || b `precedes` a  -- | Not comparable, i. e. ¬(a ≤ b) ∧ ¬(b ≤ a). concurrent :: CausalOrd a => a -> a -> Bool
lib/CRDT/Cm/Counter.hs view
@@ -21,4 +21,4 @@  -- | Empty order, allowing arbitrary reordering instance CausalOrd (Counter a) where-    affects _ _ = False+    precedes _ _ = False
lib/CRDT/Cm/GSet.hs view
@@ -18,4 +18,4 @@     apply (Add a) = Set.insert a  instance Eq a => CausalOrd (GSet a) where-    affects _ _ = False+    precedes _ _ = False
lib/CRDT/Cm/TwoPSet.hs view
@@ -27,5 +27,5 @@         Remove a  -> Set.delete a  instance Eq a => CausalOrd (TwoPSet a) where-    Remove a `affects` Add b = a == b -- `Remove e` can occur only after `Add e`-    _        `affects` _     = False  -- Any other are not ordered+    Add b `precedes` Remove a = a == b -- `Remove e` can occur only after `Add e`+    _     `precedes` _        = False  -- Any other are not ordered
lib/CRDT/LWW.hs view
@@ -64,7 +64,7 @@ -- CmRDT -----------------------------------------------------------------------  instance CausalOrd (LWW a) where-    affects _ _ = False+    precedes _ _ = False  instance Eq a => CmRDT (LWW a) where     type Intent  (LWW a) = a
test/Laws.hs view
@@ -10,6 +10,7 @@     ) where  import           Control.Monad.State.Strict (StateT, evalStateT)+import           Data.Maybe (fromMaybe) import           Data.Semigroup (Semigroup, (<>)) import           Test.QuickCheck (Arbitrary (..), Gen, Property, discard,                                   forAll, property, (===), (==>))@@ -72,17 +73,15 @@     )     => Property cmrdtLaw = property $ \(s :: Payload op) in1 in2 pid1 pid2 ->-    whenJust (makeOp @op in1 s) $ \getOp1 ->-    whenJust (makeOp @op in2 s) $ \getOp2 -> let-        (op1, op2) =-            runLamportClock $-            (,) <$> runProcess pid1 getOp1 <*> runProcess pid2 getOp2-        in-        concurrent op1 op2 ==>+    fromMaybe discard $ do+        getOp1 <- makeOp @op in1 s+        getOp2 <- makeOp @op in2 s+        let (op1, op2) =+                runLamportClock $+                (,) <$> runProcess pid1 getOp1 <*> runProcess pid2 getOp2+        pure $+            concurrent op1 op2 ==>             (apply op1 . apply op2) s === (apply op2 . apply op1) s-  where-    whenJust Nothing  _ = discard-    whenJust (Just a) f = f a  uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d uncurry3 f (a, b, c) = f a b c