package rocq-runtime

  1. Overview
  2. Docs
The Rocq Prover -- Core Binaries and Tools

Install

dune-project
 Dependency

Authors

Maintainers

Sources

rocq-9.2.0.tar.gz
sha256=a45280ab4fbaac7540b136a6b073b4a6db15739ec1e149bded43fa6f4fc25f20

doc/src/rocq-runtime.clib/writeOnceArray.ml.html

Source file writeOnceArray.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(************************************************************************)
(*         *      The Rocq Prover / The Rocq Development Team           *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)


type 'a t = 'a option array option ref

let return a : 'a t = ref (Some a)

let if_valid (r : 'a t) =
  match !r with
  | Some a -> a
  | None -> invalid_arg "Tried to reuse invalidated NoDupArray."

(** Non-destructive get operator *)
let (let+) r f =
  f (if_valid r)

let destruct_get r =
  let+ a = r in
  r := None;
  a

(** Destructive get operator *)
let (let-) r f =
  f (destruct_get r)

let update r f : 'b t =
  let- a = r in
  return (f a)

(** Updating functor operator *)
let (let*) = update


let make n = return (Array.make n None)

let get i a =
  let+ a = a in
  a.(i)

let is_filled i a =
  let+ a = a in
  Option.has_some a.(i)

let add i e a =
  let* a = a in
  begin match a.(i) with
  | None -> a.(i) <- Some e
  | Some _ -> invalid_arg "Tried to add duplicate in NoDupArray."
  end;
  a

let fill_remaining e a =
  let* a = a in
  Array.iteri (fun i elt ->
    begin match elt with
    | None -> a.(i) <- Some e
    | Some _ -> ()
    end) a;
  a

let to_array a =
  let- a = a in
  Array.map (function Some e -> e | None -> invalid_arg "Tried to cast non-full NoDupArray.") a

let to_array_opt a =
  let- a = a in
  let exception Stop in
  try Some (Array.map (function Some e -> e | None -> raise Stop) a)
  with Stop -> None

module Internal = struct

  let unsafe_to_array = if_valid
end