summaryrefslogtreecommitdiff
path: root/engine/sigma.ml
blob: 9381a33af15c0c5f1edbb6c1be5b50b12ab727f9 (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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, *   INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015     *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

type 'a t = Evd.evar_map

type ('a, 'b) le = unit

let refl = ()
let cons _ _  = ()
let (+>) = fun _ _ -> ()

type ('a, 'r) sigma = Sigma : 'a * 's t * ('r, 's) le -> ('a, 'r) sigma

type 'a evar = Evar.t

let lift_evar evk () = evk

let to_evar_map evd = evd
let to_evar evk = evk

let here x s = Sigma (x, s, ())

(** API *)

type 'r fresh = Fresh : 's evar * 's t * ('r, 's) le -> 'r fresh

let new_evar sigma ?naming info =
  let (sigma, evk) = Evd.new_evar sigma ?naming info in
  Fresh (evk, sigma, ())

let define evk c sigma =
  Sigma ((), Evd.define evk c sigma, ())

let new_univ_level_variable ?loc ?name rigid sigma =
  let (sigma, u) = Evd.new_univ_level_variable ?loc ?name rigid sigma in
  Sigma (u, sigma, ())

let new_univ_variable ?loc ?name rigid sigma =
  let (sigma, u) = Evd.new_univ_variable ?loc ?name rigid sigma in
  Sigma (u, sigma, ())

let new_sort_variable ?loc ?name rigid sigma =
  let (sigma, u) = Evd.new_sort_variable ?loc ?name rigid sigma in
  Sigma (u, sigma, ())

let fresh_sort_in_family ?loc ?rigid env sigma s =
  let (sigma, s) = Evd.fresh_sort_in_family ?loc ?rigid env sigma s in
  Sigma (s, sigma, ())

let fresh_constant_instance ?loc env sigma cst =
  let (sigma, cst) = Evd.fresh_constant_instance ?loc env sigma cst in
  Sigma (cst, sigma, ())

let fresh_inductive_instance ?loc env sigma ind =
  let (sigma, ind) = Evd.fresh_inductive_instance ?loc env sigma ind in
  Sigma (ind, sigma, ())

let fresh_constructor_instance ?loc env sigma pc =
  let (sigma, c) = Evd.fresh_constructor_instance ?loc env sigma pc in
  Sigma (c, sigma, ())

let fresh_global ?loc ?rigid ?names env sigma r =
  let (sigma, c) = Evd.fresh_global ?loc ?rigid ?names env sigma r in
  Sigma (c, sigma, ())

(** Run *)

type 'a run = { run : 'r. 'r t -> ('a, 'r) sigma }

let run sigma f : 'a * Evd.evar_map =
  let Sigma (x, sigma, ()) = f.run sigma in
  (x, sigma)

(** Monotonic references *)

type evdref = Evd.evar_map ref

let apply evdref f =
  let Sigma (x, sigma, ()) = f.run !evdref in
  evdref := sigma;
  x

let purify f =
  let f (sigma : Evd.evar_map) =
    let evdref = ref sigma in
    let ans = f evdref in
    Sigma (ans, !evdref, ())
  in
  { run = f }

(** Unsafe primitives *)

module Unsafe =
struct

let le = ()
let of_evar_map sigma = sigma
let of_evar evk = evk
let of_ref ref = ref
let of_pair (x, sigma) = Sigma (x, sigma, ())

end

module Notations =
struct
  type ('a, 'r) sigma_ = ('a, 'r) sigma =
    Sigma : 'a * 's t * ('r, 's) le -> ('a, 'r) sigma_

  let (+>) = fun _ _ -> ()

  type 'a run_ = 'a run = { run : 'r. 'r t -> ('a, 'r) sigma }
end