blob: e89f05a723e2c19c57d5ef6847d52137a664fc75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|