summaryrefslogtreecommitdiff
path: root/lib/value/property.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-11-22 13:58:16 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-11-22 13:58:16 +0100
commit056fcabaeec238a7aa927df39a90acea028b1aa0 (patch)
tree3246359561eb2375e85da4537e05a083a1348467 /lib/value/property.ml
parentbc78bea63b7c75e8a9d222dc86fb75ed293a2242 (diff)
Added an option for loading a value content without the multivaluated fields (allow single query)main
Diffstat (limited to 'lib/value/property.ml')
-rw-r--r--lib/value/property.ml36
1 files changed, 36 insertions, 0 deletions
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