]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic/libraryObjects.ml
Big commit to let Ferruccio try the merge_coercion patch.
[helm.git] / helm / ocaml / cic / libraryObjects.ml
1 (* Copyright (C) 2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 (**** TABLES ****)
27
28 let default_eq_URIs =
29  [HelmLibraryObjects.Logic.eq_URI,
30       HelmLibraryObjects.Logic.sym_eq_URI,
31       HelmLibraryObjects.Logic.trans_eq_URI,
32       HelmLibraryObjects.Logic.eq_ind_URI,
33       HelmLibraryObjects.Logic.eq_ind_r_URI];;
34
35 let default_true_URIs = [HelmLibraryObjects.Logic.true_URI]
36 let default_false_URIs = [HelmLibraryObjects.Logic.false_URI]
37 let default_absurd_URIs = [HelmLibraryObjects.Logic.absurd_URI]
38
39 (* eq, sym_eq, trans_eq, eq_ind, eq_ind_R *)
40 let eq_URIs_ref =
41  ref [HelmLibraryObjects.Logic.eq_URI,
42       HelmLibraryObjects.Logic.sym_eq_URI,
43       HelmLibraryObjects.Logic.trans_eq_URI,
44       HelmLibraryObjects.Logic.eq_ind_URI,
45       HelmLibraryObjects.Logic.eq_ind_r_URI];;
46
47 let true_URIs_ref = ref [HelmLibraryObjects.Logic.true_URI]
48 let false_URIs_ref = ref [HelmLibraryObjects.Logic.false_URI]
49 let absurd_URIs_ref = ref [HelmLibraryObjects.Logic.absurd_URI]
50
51
52 (**** SET_DEFAULT ****)
53
54 exception NotRecognized;;
55
56 (* insert an element in front of the list, removing from the list all the
57    previous elements with the same key associated *)
58 let insert_unique e extract l =
59  let uri = extract e in
60  let l' =
61   List.filter (fun x -> let uri' = extract x in not (UriManager.eq uri uri')) l
62  in
63   e :: l'
64
65 let set_default what l =
66   match what,l with
67     "equality",[eq_URI;sym_eq_URI;trans_eq_URI;eq_ind_URI;eq_ind_r_URI] ->
68       eq_URIs_ref :=
69        insert_unique (eq_URI,sym_eq_URI,trans_eq_URI,eq_ind_URI,eq_ind_r_URI)
70         (fun x,_,_,_,_ -> x) !eq_URIs_ref
71   | "true",[true_URI] ->
72       true_URIs_ref := insert_unique true_URI (fun x -> x) !true_URIs_ref
73   | "false",[false_URI] ->
74       false_URIs_ref := insert_unique false_URI (fun x -> x) !false_URIs_ref
75   | "absurd",[absurd_URI] ->
76       absurd_URIs_ref := insert_unique absurd_URI (fun x -> x) !absurd_URIs_ref
77   | _,_ -> raise NotRecognized
78
79 let reset_defaults () =
80   eq_URIs_ref := default_eq_URIs;
81   true_URIs_ref := default_true_URIs;
82   false_URIs_ref := default_false_URIs;
83   absurd_URIs_ref := default_absurd_URIs
84
85 (**** LOOKUP FUNCTIONS ****)
86
87 let eq_URI () = let eq,_,_,_,_ = List.hd !eq_URIs_ref in eq
88
89 let is_eq_URI uri =
90  List.exists (fun (eq,_,_,_,_) -> UriManager.eq eq uri) !eq_URIs_ref
91
92 let sym_eq_URI ~eq:uri =
93  try
94   let _,x,_,_,_ = List.find (fun eq,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
95  with Not_found -> raise NotRecognized
96
97 let trans_eq_URI ~eq:uri =
98  try
99   let _,_,x,_,_ = List.find (fun eq,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
100  with Not_found -> raise NotRecognized
101
102 let eq_ind_URI ~eq:uri =
103  try
104   let _,_,_,x,_ = List.find (fun eq,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
105  with Not_found -> raise NotRecognized
106
107 let eq_ind_r_URI ~eq:uri =
108  try
109   let _,_,_,_,x = List.find (fun eq,_,_,_,_ -> UriManager.eq eq uri) !eq_URIs_ref in x
110  with Not_found -> raise NotRecognized
111
112 let true_URI () = List.hd !true_URIs_ref
113 let false_URI () = List.hd !false_URIs_ref
114 let absurd_URI () = List.hd !absurd_URIs_ref