val ok : 'a -> ('a, conflict) Stdlib.result Lwt.t
Return Ok x
.
val conflict : ('a, unit, string, ('b, conflict) Stdlib.result Lwt.t) Stdlib.format4 -> 'a
Return Error (Conflict str)
.
val bind : ('a, 'b) Stdlib.result Lwt.t -> ('a -> ('c, 'b) Stdlib.result Lwt.t) -> ('c, 'b) Stdlib.result Lwt.t
bind r f
is the merge result which behaves as of the application of the function f
to the return value of r
. If r
fails, bind r f
also fails, with the same conflict.
val map : ('a -> 'c) -> ('a, 'b) Stdlib.result Lwt.t -> ('c, 'b) Stdlib.result Lwt.t
map f m
maps the result of a merge. This is the same as bind m (fun x -> ok (f x))
.
Merge Combinators
type 'a promise = unit -> ('a option, conflict) Stdlib.result Lwt.t
An 'a
promise is a function which, when called, will eventually return a value type of 'a
. A promise is an optional, lazy and non-blocking value.
val promise : 'a -> 'a promise
promise a
is the promise containing a
.
map_promise f a
is the promise containing f
applied to what is promised by a
.
bind_promise a f
is the promise returned by f
applied to what is promised by a
.
type 'a f = old:'a promise -> 'a -> 'a -> ('a, conflict) Stdlib.result Lwt.t
Signature of a merge function. old
is the value of the least-common ancestor.
/----> t1 ----\ ----> old |--> result \----> t2 ----/
Call the merge functions in sequence. Stop as soon as one is not returning a conflict.
Use the merge function defined in another domain. If the converting functions raise any exception the merge is a conflict.
with_conflict f m
is m
with the conflict error message modified by f
.
Same as biject but with blocking domain converting functions.
Basic Merges
default t
is the default merge function for values of type t
. This is a simple merge function which supports changes in one branch at a time:
- if
t1=old
then the result of the merge isOK t2
; - if
t2=old
then returnOK t1
; - otherwise the result is
Conflict
.
idempotent t
is the default merge function for values of type t
using idempotent operations. It follows the same rules as the default
merge function but also adds:
- if
t1=t2
then the result of the merge isOK t1
.
val unit : unit t
unit
is the default merge function for unit values.
val bool : bool t
bool
is the default merge function for booleans.
val char : char t
char
is the default merge function for characters.
val int32 : int32 t
int32
is the default merge function for 32-bits integers.
val int64 : int64 t
int64
the default merge function for 64-bit integers.
val float : float t
float
is the default merge function for floating point numbers.
val string : string t
The default string merge function. Do not do anything clever, just compare the strings using the default
merge function.
Lift a merge function to optional values of the same type. If all the provided values are inhabited, then call the provided merge function, otherwise use the same behavior as default
.
Counters and Multisets
The type for counter values. It is expected that the only valid operations on counters are increment and decrement. The following merge functions ensure that the counter semantics are preserved: i.e. it ensures that the number of increments and decrements is preserved.
Maps and Association Lists
Lift the merge functions to association lists.
Value Types
val result_t : 'a Type.t -> ('a, conflict) Stdlib.result Type.t
result_t
is the value type for merge results.