crjdt-haskell

A Conflict-Free Replicated JSON Datatype for Haskell https://github.com/amarpotghan/crjdt-haskell#readme

Latest on Hackage:0.3.0

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD3 licensed by Amar Potghan
Maintained by amarpotghan@gmail.com

Build Status

A Conflict-Free Replicated JSON Datatype for Haskell

crjdt-haskell provides high level interface to CRDT which is formalised in the paper by Martin Kleppmann and Alastair R. Beresford.

Documentation

See haddocks.

Example


{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.Crjdt as C

-- Original state
original :: Command ()
original = doc .> key "key" =: "A"

-- First replica updates doc["key"] to "B"
replica1 :: Command ()
replica1 = original *> doc .> key "key" =: "B"

-- Second replica updates doc["key"] to "C"
replica2 :: Command ()
replica2 = original *> doc .> key "key" =: "C"

main :: IO ()
main = do
  -- Sync first and second replica
  let Right (r1, r2) = sync (1, replica1) (2, replica2)

  let replica1' = execEval 1 r1
      replica2' = execEval 2 r2

  -- Both replicas converge to: {"key": {"B", "C"}}
  print (document replica1' == document replica2') -- True

Future work

  • Improve documentation
  • Aeson support
  • Simplify API as described in second version of the paper

Other implementations

LICENSE

Copyright © 2017 Amar Potghan

Distributed under BSD License.

Changes

0.3.0

  • BREAKING CHANGE: Remove unnecessarry exports
  • BREAKING CHANGE: Fix fixity of (.>), it now binds more tightly than (=:)

0.2.1

  • Generalize helper function sync

0.2.0

  • BREAKING CHANGE: helper function sync is not IO anymore

0.1.0

  • Initial release
Depends on 5 packages:
Used by 1 package:
comments powered byDisqus