jon.recoil.org

Source file type.ml

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
37
38
39
40
41
42
43
44
45
46
47
48
(**************************************************************************)
(*                                                                        *)
(*                                 OCaml                                  *)
(*                                                                        *)
(*                         The OCaml programmers                          *)
(*                                                                        *)
(*   Copyright 2022 Institut National de Recherche en Informatique et     *)
(*     en Automatique.                                                    *)
(*                                                                        *)
(*   All rights reserved.  This file is distributed under the terms of    *)
(*   the GNU Lesser General Public License version 2.1, with the          *)
(*   special exception on linking described in the file LICENSE.          *)
(*                                                                        *)
(**************************************************************************)

open! Stdlib

(* Type equality witness *)

type (_ : value_or_null, _ : value_or_null) eq =
  Equal: ('a : value_or_null) . ('a , 'a) eq

(* Type identifiers *)

module Id = struct
  type (_ : value_or_null) id = ..
  module type ID = sig
    type t : value_or_null
    type _ id += Id : t id
  end

  type (!'a : value_or_null) t : immutable_data =
    T : ('a : value_or_null).
      (module ID with type t = 'a) -> 'a t [@@unboxed]
  [@@unsafe_allow_any_mode_crossing]

  let make (type a : value_or_null) () : a t =
    T (module struct type t = a type _ id += Id : t id end)

  let[@inline] uid (type a : value_or_null) (T (module A) : a t) =
    Obj.Extension_constructor.id (Obj.Extension_constructor.of_val A.Id)

  let provably_equal
      (type a : value_or_null) (type b : value_or_null)
      (T (module A) : a t) (T (module B) : b t) : (a, b) eq option
    =
    match A.Id with B.Id -> Some Equal | _ -> None
end