~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to interp/coqlib.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(************************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
 
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
 
4
(*   \VV/  **************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the       *)
 
6
(*         *       GNU Lesser General Public License Version 2.1        *)
 
7
(************************************************************************)
 
8
 
 
9
(* $Id: coqlib.ml 11309 2008-08-06 10:30:35Z herbelin $ *)
 
10
 
 
11
open Util
 
12
open Pp
 
13
open Names
 
14
open Term
 
15
open Libnames
 
16
open Pattern
 
17
open Nametab
 
18
 
 
19
(************************************************************************)
 
20
(* Generic functions to find Coq objects *)
 
21
 
 
22
type message = string
 
23
 
 
24
let make_dir l = make_dirpath (List.map id_of_string (List.rev l))
 
25
 
 
26
let find_reference locstr dir s =
 
27
  let sp = Libnames.make_path (make_dir dir) (id_of_string s) in
 
28
  try
 
29
    Nametab.absolute_reference sp
 
30
  with Not_found ->
 
31
    anomaly (locstr^": cannot find "^(string_of_path sp))
 
32
 
 
33
let coq_reference locstr dir s = find_reference locstr ("Coq"::dir) s
 
34
let coq_constant locstr dir s = constr_of_global (coq_reference locstr dir s)
 
35
 
 
36
let gen_reference = coq_reference
 
37
let gen_constant = coq_constant
 
38
 
 
39
let has_suffix_in_dirs dirs ref =
 
40
  let dir = dirpath (sp_of_global ref) in
 
41
  List.exists (fun d -> is_dirpath_prefix_of d dir) dirs
 
42
 
 
43
let gen_constant_in_modules locstr dirs s =
 
44
  let dirs = List.map make_dir dirs in
 
45
  let id = id_of_string s in
 
46
  let all = Nametab.locate_all (make_short_qualid id) in
 
47
  let these = List.filter (has_suffix_in_dirs dirs) all in
 
48
  match these with
 
49
    | [x] -> constr_of_global x
 
50
    | [] ->
 
51
        anomalylabstrm "" (str (locstr^": cannot find "^s^
 
52
        " in module"^(if List.length dirs > 1 then "s " else " ")) ++
 
53
        prlist_with_sep pr_coma pr_dirpath dirs)
 
54
    | l ->
 
55
        anomalylabstrm "" 
 
56
        (str (locstr^": found more than once object of name "^s^
 
57
        " in module"^(if List.length dirs > 1 then "s " else " ")) ++
 
58
        prlist_with_sep pr_coma pr_dirpath dirs)
 
59
 
 
60
 
 
61
(* For tactics/commands requiring vernacular libraries *)
 
62
 
 
63
let check_required_library d =
 
64
  let d' = List.map id_of_string d in
 
65
  let dir = make_dirpath (List.rev d') in
 
66
  if not (Library.library_is_loaded dir) then
 
67
(* Loading silently ...
 
68
    let m, prefix = list_sep_last d' in
 
69
    read_library 
 
70
     (dummy_loc,make_qualid (make_dirpath (List.rev prefix)) m)
 
71
*)
 
72
(* or failing ...*)
 
73
    error ("Library "^(string_of_dirpath dir)^" has to be required first.")
 
74
 
 
75
(************************************************************************)
 
76
(* Specific Coq objects *)
 
77
 
 
78
let init_reference dir s = gen_reference "Coqlib" ("Init"::dir) s
 
79
 
 
80
let init_constant dir s = gen_constant "Coqlib" ("Init"::dir) s  
 
81
 
 
82
let arith_dir = ["Coq";"Arith"]
 
83
let arith_modules = [arith_dir]
 
84
 
 
85
let narith_dir = ["Coq";"NArith"]
 
86
 
 
87
let zarith_dir = ["Coq";"ZArith"]
 
88
let zarith_base_modules = [narith_dir;zarith_dir]
 
89
 
 
90
let init_dir = ["Coq";"Init"]
 
91
let init_modules = [
 
92
  init_dir@["Datatypes"];
 
93
  init_dir@["Logic"];
 
94
  init_dir@["Specif"];
 
95
  init_dir@["Logic_Type"];
 
96
  init_dir@["Peano"];
 
97
  init_dir@["Wf"]
 
98
]
 
99
  
 
100
let coq_id = id_of_string "Coq"
 
101
let init_id = id_of_string "Init"
 
102
let arith_id = id_of_string "Arith"
 
103
let datatypes_id = id_of_string "Datatypes"
 
104
 
 
105
let logic_module_name = ["Coq";"Init";"Logic"]
 
106
let logic_module = make_dir logic_module_name
 
107
let logic_type_module = make_dir ["Coq";"Init";"Logic_Type"]
 
108
let datatypes_module = make_dir ["Coq";"Init";"Datatypes"]
 
109
let arith_module = make_dir ["Coq";"Arith";"Arith"]
 
110
 
 
111
(* TODO: temporary hack *)
 
112
let make_kn dir id = Libnames.encode_kn dir id
 
113
let make_con dir id = Libnames.encode_con dir id
 
114
 
 
115
(** Identity *)
 
116
 
 
117
let id = make_con datatypes_module (id_of_string "id")
 
118
let type_of_id = make_con datatypes_module (id_of_string "ID")
 
119
 
 
120
let _ = Cases.set_impossible_default_clause (mkConst id,mkConst type_of_id)
 
121
 
 
122
(** Natural numbers *)
 
123
let nat_kn = make_kn datatypes_module (id_of_string "nat")
 
124
let nat_path = Libnames.make_path datatypes_module (id_of_string "nat")
 
125
 
 
126
let glob_nat = IndRef (nat_kn,0)
 
127
 
 
128
let path_of_O = ((nat_kn,0),1)
 
129
let path_of_S = ((nat_kn,0),2)
 
130
let glob_O = ConstructRef path_of_O
 
131
let glob_S = ConstructRef path_of_S
 
132
 
 
133
(** Booleans *)
 
134
let bool_kn = make_kn datatypes_module (id_of_string "bool")
 
135
 
 
136
let glob_bool = IndRef (bool_kn,0)
 
137
 
 
138
let path_of_true = ((bool_kn,0),1)
 
139
let path_of_false = ((bool_kn,0),2)
 
140
let glob_true  = ConstructRef path_of_true
 
141
let glob_false  = ConstructRef path_of_false
 
142
 
 
143
(** Equality *)
 
144
let eq_kn = make_kn logic_module (id_of_string "eq")
 
145
 
 
146
let glob_eq = IndRef (eq_kn,0)
 
147
 
 
148
type coq_sigma_data = {
 
149
  proj1 : constr;
 
150
  proj2 : constr;
 
151
  elim  : constr;
 
152
  intro : constr;
 
153
  typ   : constr }
 
154
 
 
155
type coq_bool_data  = {
 
156
  andb : constr;
 
157
  andb_prop : constr;
 
158
  andb_true_intro : constr}
 
159
 
 
160
type 'a delayed = unit -> 'a
 
161
 
 
162
let build_bool_type () = 
 
163
  { andb =  init_constant ["Datatypes"] "andb";
 
164
    andb_prop =  init_constant ["Datatypes"] "andb_prop";
 
165
    andb_true_intro =  init_constant ["Datatypes"] "andb_true_intro" }
 
166
 
 
167
 
 
168
let build_sigma_set () = anomaly "Use build_sigma_type"
 
169
 
 
170
let build_sigma_type () =
 
171
  { proj1 = init_constant ["Specif"] "projT1";
 
172
    proj2 = init_constant ["Specif"] "projT2";
 
173
    elim = init_constant ["Specif"] "sigT_rec";
 
174
    intro = init_constant ["Specif"] "existT";
 
175
    typ = init_constant ["Specif"] "sigT" }
 
176
 
 
177
let build_prod () =
 
178
  { proj1 = init_constant ["Datatypes"] "fst";
 
179
    proj2 = init_constant ["Datatypes"] "snd";
 
180
    elim = init_constant ["Datatypes"] "prod_rec";
 
181
    intro = init_constant ["Datatypes"] "pair";
 
182
    typ = init_constant ["Datatypes"] "prod" }
 
183
 
 
184
(* Equalities *)
 
185
type coq_leibniz_eq_data = {
 
186
  eq   : constr;
 
187
  refl : constr;
 
188
  ind  : constr;
 
189
  rrec : constr option;
 
190
  rect : constr option;
 
191
  congr: constr;
 
192
  sym  : constr }
 
193
 
 
194
let lazy_init_constant dir id = lazy (init_constant dir id)
 
195
 
 
196
(* Equality on Set *)
 
197
let coq_eq_eq = lazy_init_constant ["Logic"] "eq"
 
198
let coq_eq_refl = lazy_init_constant ["Logic"] "refl_equal"
 
199
let coq_eq_ind = lazy_init_constant ["Logic"] "eq_ind"
 
200
let coq_eq_rec = lazy_init_constant ["Logic"] "eq_rec"
 
201
let coq_eq_rect = lazy_init_constant ["Logic"] "eq_rect"
 
202
let coq_eq_congr = lazy_init_constant ["Logic"] "f_equal"
 
203
let coq_eq_sym  = lazy_init_constant ["Logic"] "sym_eq"
 
204
let coq_f_equal2 = lazy_init_constant ["Logic"] "f_equal2"
 
205
 
 
206
let build_coq_eq_data () =
 
207
  let _ = check_required_library logic_module_name in {
 
208
  eq = Lazy.force coq_eq_eq;
 
209
  refl = Lazy.force coq_eq_refl;
 
210
  ind = Lazy.force coq_eq_ind;
 
211
  rrec = Some (Lazy.force coq_eq_rec);
 
212
  rect = Some (Lazy.force coq_eq_rect);
 
213
  congr = Lazy.force coq_eq_congr;
 
214
  sym = Lazy.force coq_eq_sym }
 
215
 
 
216
let build_coq_eq () = Lazy.force coq_eq_eq
 
217
let build_coq_sym_eq () = Lazy.force coq_eq_sym
 
218
let build_coq_f_equal2 () = Lazy.force coq_f_equal2
 
219
 
 
220
(* Specif *)
 
221
let coq_sumbool  = lazy_init_constant ["Specif"] "sumbool"
 
222
 
 
223
let build_coq_sumbool () = Lazy.force coq_sumbool
 
224
 
 
225
(* Equality on Type as a Type *)
 
226
let coq_identity_eq = lazy_init_constant ["Datatypes"] "identity"
 
227
let coq_identity_refl = lazy_init_constant ["Datatypes"] "refl_identity"
 
228
let coq_identity_ind = lazy_init_constant ["Datatypes"] "identity_ind"
 
229
let coq_identity_rec = lazy_init_constant ["Datatypes"] "identity_rec"
 
230
let coq_identity_rect = lazy_init_constant ["Datatypes"] "identity_rect"
 
231
let coq_identity_congr = lazy_init_constant ["Logic_Type"] "congr_id"
 
232
let coq_identity_sym = lazy_init_constant ["Logic_Type"] "sym_id"
 
233
 
 
234
let build_coq_identity_data () = {
 
235
  eq = Lazy.force coq_identity_eq;
 
236
  refl = Lazy.force coq_identity_refl;
 
237
  ind = Lazy.force coq_identity_ind;
 
238
  rrec = Some (Lazy.force coq_identity_rec);
 
239
  rect = Some (Lazy.force coq_identity_rect);
 
240
  congr = Lazy.force coq_identity_congr;
 
241
  sym = Lazy.force coq_identity_sym }
 
242
 
 
243
(* The False proposition *)
 
244
let coq_False  = lazy_init_constant ["Logic"] "False"
 
245
 
 
246
(* The True proposition and its unique proof *)
 
247
let coq_True   = lazy_init_constant ["Logic"] "True"
 
248
let coq_I      = lazy_init_constant ["Logic"] "I"
 
249
 
 
250
(* Connectives *)
 
251
let coq_not = lazy_init_constant ["Logic"] "not"
 
252
let coq_and = lazy_init_constant ["Logic"] "and"
 
253
let coq_conj = lazy_init_constant ["Logic"] "conj"
 
254
let coq_or = lazy_init_constant ["Logic"] "or"
 
255
let coq_ex = lazy_init_constant ["Logic"] "ex"
 
256
 
 
257
(* Runtime part *)
 
258
let build_coq_True ()  = Lazy.force coq_True
 
259
let build_coq_I ()     = Lazy.force coq_I
 
260
 
 
261
let build_coq_False () = Lazy.force coq_False
 
262
let build_coq_not ()   = Lazy.force coq_not
 
263
let build_coq_and ()   = Lazy.force coq_and
 
264
let build_coq_conj ()  = Lazy.force coq_conj
 
265
let build_coq_or ()   = Lazy.force coq_or
 
266
let build_coq_ex ()   = Lazy.force coq_ex
 
267
 
 
268
(* The following is less readable but does not depend on parsing *)
 
269
let coq_eq_ref      = lazy (init_reference ["Logic"] "eq")
 
270
let coq_identity_ref     = lazy (init_reference ["Datatypes"] "identity")
 
271
let coq_existS_ref  = lazy (anomaly "use coq_existT_ref")
 
272
let coq_existT_ref  = lazy (init_reference ["Specif"] "existT")
 
273
let coq_not_ref     = lazy (init_reference ["Logic"] "not")
 
274
let coq_False_ref   = lazy (init_reference ["Logic"] "False")
 
275
let coq_sumbool_ref = lazy (init_reference ["Specif"] "sumbool")
 
276
let coq_sig_ref = lazy (init_reference ["Specif"] "sig")
 
277
let coq_or_ref     = lazy (init_reference ["Logic"] "or")
 
278