From 056fcabaeec238a7aa927df39a90acea028b1aa0 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Sun, 22 Nov 2026 13:58:16 +0100 Subject: Added an option for loading a value content without the multivaluated fields (allow single query) --- lib/model/types.ml | 50 ++++++-------------------------------------------- 1 file changed, 6 insertions(+), 44 deletions(-) (limited to 'lib/model/types.ml') diff --git a/lib/model/types.ml b/lib/model/types.ml index ee244d3..7226d6f 100644 --- a/lib/model/types.ml +++ b/lib/model/types.ml @@ -49,8 +49,12 @@ let default_value : type a b c. (a, b, c) t -> a = function | MonoReference _ -> None | MultiReference _ -> raise Not_found -(** Constructor-level equality on the ['db] representation *) -let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = +(** Constructor-level equality: [eq t1 t2] is [Some Equal] when [t1] and [t2] + have the same constructor. The pair ['a * 'x] is injective, so [Equal] + proves both ['a = 'b] (the database representations) and ['x = 'y] (the code + representations) at once *) +let eq : type a b x y c. + (a, x, c) t -> (b, y, c) t -> (a * x, b * y) Type.eq option = fun t1 t2 -> match (t1, t2) with | MultiReference _, MultiReference _ -> Some Type.Equal @@ -58,45 +62,3 @@ let eq : type a b x y c. (a, x, c) t -> (b, y, c) t -> (a, b) Type.eq option = | Integer, Integer -> Some Type.Equal | Text, Text -> Some Type.Equal | _ -> None - -(** Constructor-level equality on the ['ocaml] representation *) -let eq_ocaml : type a b x y c. - (a, x, c) t -> (b, y, c) t -> (x, y) Type.eq option = - fun t1 t2 -> - match (t1, t2) with - | MultiReference _, MultiReference _ -> Some Type.Equal - | MonoReference _, MonoReference _ -> Some Type.Equal - | Integer, Integer -> Some Type.Equal - | Text, Text -> Some Type.Equal - | _ -> None - -type 'typ named = { - name : Identifier.t; (** The internal name of the field *) - typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) -} -(** A named field type: a {!t} together with the field's name. - - Named types are built on the fly with {!named} (e.g. from a field, see - {!Field.named_of}) and used locally as typed handles — e.g. to read the data - of a field from a value. A pre-built instance exists for the reserved field - [["id"]] (see [Value.id_ref]). *) - -(** Build a named type from a name and a type — no uniqueness involved, so - values built on the fly denote the same field *) -let named : name:Identifier.t -> typ:'typ -> 'typ named = - fun ~name ~typ -> { name; typ } - -let name : 'typ named -> Identifier.t = fun n -> n.name -let typ : 'typ named -> 'typ = fun n -> n.typ - -(** [provably_equal n1 n2] is [Some Equal] iff [n1] and [n2] denote the same - field — same name — and their types match, which also proves that their - ['ocaml] representations are equal *) -let provably_equal (type a b x y c) (n1 : (a, x, c) t named) - (n2 : (b, y, c) t named) : (x, y) Type.eq option = - if Identifier.equal n1.name n2.name then eq_ocaml n1.typ n2.typ else None - -(** [same n1 n2] is [true] iff [n1] and [n2] denote the same field with matching - types *) -let same : ('a, 'x, 'c) t named -> ('b, 'y, 'c) t named -> bool = - fun n1 n2 -> provably_equal n1 n2 <> None -- cgit v1.2.3