diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-20 16:23:53 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-20 16:23:53 +0100 |
| commit | b05e2d2be7be28ee6c577671002797cf9abaf177 (patch) | |
| tree | 0474684d619721024f0a6cb132cf2f4d2e84c344 /lib/value/data.ml | |
| parent | c4ca180fd7c2085e3ce3f8e32aa0c2cb724f4c53 (diff) | |
New module for working with Values
Diffstat (limited to 'lib/value/data.ml')
| -rw-r--r-- | lib/value/data.ml | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/value/data.ml b/lib/value/data.ml new file mode 100644 index 0000000..7cbc00f --- /dev/null +++ b/lib/value/data.ml @@ -0,0 +1,28 @@ +(** The data carried by a field of a value. + + [None] tells the field is empty (or left as is, on update), [V] carries a + single value together with the type of its field, and [Seq] carries a + sequence of references for a multivalued field. + + The type is parameterized over the type of the data held (['a]: the DB + representation of the field, e.g. [string option] or [int64 option]) and + over ['t], the target of the field for references — a reference is held as + an [int64] (the id of the target row), while ['t] records what it points + to. The field type {!Model.Typ.t} stays in the model package; only the data + itself lives here. *) +type ('a, 't) data = + | None + | V : ('a, 't) Model.Typ.t * 'a -> ('a, 't) data + | Seq : (int64, 't) Model.Typ.t * int64 Seq.t -> (int64 Seq.t, 't) data + +let none : ('a, 't) data = None + +let v : ('a, 't) Model.Typ.t * 'a -> ('a, 't) data = + fun (typ, value) -> V (typ, value) + +let seq : (int64, 't) Model.Typ.t * int64 Seq.t -> (int64 Seq.t, 't) data = + fun (typ, values) -> Seq (typ, values) + +type 't any = Any : ('a, 't) data -> 't any [@@unboxed] + +let any : ('a, 't) data -> 't any = fun data -> Any data |
