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/value/property.ml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 lib/value/property.ml (limited to 'lib/value/property.ml') diff --git a/lib/value/property.ml b/lib/value/property.ml new file mode 100644 index 0000000..e89f05a --- /dev/null +++ b/lib/value/property.ml @@ -0,0 +1,36 @@ +type 'typ t = { + name : Model.Identifier.t; (** The internal name of the field *) + typ : 'typ; (** The type of the field, e.g. a ['target multireference] *) +} +(** A property of a value: a field name tied to its type — a {!Model.Types.t} + together with the field's {!Model.Identifier.t}. + + Properties are built on the fly with {!named} 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 {[id_ref]} in the main + module of this package). *) + +(** Build a property from a name and a type — no uniqueness involved, so values + built on the fly denote the same field *) +let named : name:Model.Identifier.t -> typ:'typ -> 'typ t = + fun ~name ~typ -> { name; typ } + +let name : 'typ t -> Model.Identifier.t = fun n -> n.name +let typ : 'typ t -> 'typ = fun n -> n.typ + +(** [provably_equal p1 p2] is [Some Equal] iff [p1] and [p2] 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) (p1 : (a, x, c) Model.Types.t t) + (p2 : (b, y, c) Model.Types.t t) : (x, y) Type.eq option = + if Model.Identifier.equal p1.name p2.name then + match Model.Types.eq p1.typ p2.typ with + | Some Type.Equal -> Some Type.Equal + | None -> None + else None + +(** [same p1 p2] is [true] iff [p1] and [p2] denote the same field with matching + types *) +let same : ('a, 'x, 'c) Model.Types.t t -> ('b, 'y, 'c) Model.Types.t t -> bool + = + fun p1 p2 -> provably_equal p1 p2 <> None -- cgit v1.2.3