package coq-core

  1. Overview
  2. Docs
The Coq Proof Assistant -- Core Binaries and Tools

Install

Dune Dependency

Authors

Maintainers

Sources

coq-8.20.0.tar.gz
md5=66e57ea55275903bef74d5bf36fbe0f1
sha512=1a7eac6e2f58724a3f9d68bbb321e4cfe963ba1a5551b9b011db4b3f559c79be433d810ff262593d753770ee41ea68fbd6a60daa1e2319ea00dff64c8851d70b

doc/src/ltac2_plugin/tac2externals.ml.html

Source file tac2externals.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
83
84
85
86
87
88
89
(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq 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)         *)
(************************************************************************)

open Proofview
open Tac2ffi

(* Local shortcuts. *)
type v = Tac2val.valexpr
type 'r of_v = v -> 'r
type 'r to_v = 'r -> v
type 'a with_env = Environ.env -> Evd.evar_map -> 'a

(* We use two levels of GADT to get rid of the third type parameter, which has
   to be give for this type definition to be accepted. If we remove it, we get
   an error: "a type variable cannot be deduced from the type parameters". *)
type (_, _, _) spec_aux =
  | T : 'r to_v -> (v tactic, 'r tactic, 'r) spec_aux
  | V : 'r to_v -> (v tactic, 'r, 'r) spec_aux
  | E : 'r to_v -> (v tactic, 'r with_env, 'r) spec_aux
  | G : 'r to_v -> (v tactic, Goal.t -> 'r, 'r) spec_aux
  | F : 'a of_v * ('t, 'f, 'r) spec_aux -> (v -> 't , 'a -> 'f, 'r) spec_aux

type (_,_) spec = S : ('v,'f,'r) spec_aux -> ('v,'f) spec [@@unboxed]

let tac : type r. r repr -> (v tactic, r tactic) spec = fun r ->
  S (T (repr_of r))

let tac': type r. r to_v -> (v tactic, r tactic) spec = fun tr ->
  S (T tr)

let ret : type r. r repr -> (v tactic, r) spec = fun r ->
  S (V (repr_of r))

let ret': type r. r to_v -> (v tactic, r) spec = fun tr ->
  S (V tr)

let eret : type r. r repr -> (v tactic, r with_env) spec = fun r ->
  S (E (repr_of r))

let eret': type r. r to_v -> (v tactic, r with_env) spec = fun tr ->
  S (E tr)

let gret : type r. r repr -> (v tactic, Goal.t -> r) spec = fun r ->
  S (G (repr_of r))

let gret': type r. r to_v -> (v tactic, Goal.t -> r) spec = fun tr ->
  S (G tr)

let (@->) : type a t f. a repr -> (t,f) spec -> (v -> t, a -> f) spec =
  fun r (S ar) -> S (F (repr_to r, ar))

let (@-->): type a t f. a of_v -> (t,f) spec -> (v -> t, a -> f) spec =
  fun of_v (S ar) -> S (F (of_v, ar))

let rec interp_spec : type v f. (v,f) spec -> f -> v = fun (S ar) f ->
  let open Proofview.Notations in
  match ar with
  | T tr -> f >>= fun v -> tclUNIT (tr v)
  | V tr -> tclUNIT (tr f)
  | E tr -> tclENV >>= fun e -> tclEVARMAP >>= fun s -> tclUNIT (tr (f e s))
  | G tr -> Goal.enter_one @@ fun g -> tclUNIT (tr (f g))
  | F (tr,ar) -> fun v -> interp_spec (S ar) (f (tr v))

let rec arity_of : type v f. (v,f) spec -> v Tac2val.arity = fun (S ar) ->
  match ar with
  | F (_, T _) -> Tac2val.arity_one
  | F (_, V _) -> Tac2val.arity_one
  | F (_, E _) -> Tac2val.arity_one
  | F (_, G _) -> Tac2val.arity_one
  | F (_, ar) -> Tac2val.arity_suc (arity_of (S ar))
  | _ -> invalid_arg "Tac2def.arity_of: not a function spec"

let define : type v f. _ -> (v,f) spec -> f -> unit = fun n ar v ->
  let v =
    match ar with
    | S (V tr) -> tr v
    | S (F _) ->
        let cl = Tac2val.mk_closure (arity_of ar) (interp_spec ar v) in
        Tac2ffi.of_closure cl
    | _ -> invalid_arg "Tac2def.define: not a pure value"
  in
  Tac2env.define_primitive n v
OCaml

Innovation. Community. Security.