]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/cic/cic.ml
Preparing for 0.5.9 release.
[helm.git] / helm / software / components / cic / cic.ml
1 (* Copyright (C) 2000, 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://cs.unibo.it/helm/.
24  *)
25
26 (*****************************************************************************)
27 (*                                                                           *)
28 (*                               PROJECT HELM                                *)
29 (*                                                                           *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>              *)
31 (*                                 29/11/2000                                *)
32 (*                                                                           *)
33 (* This module defines the internal representation of the objects (variables,*)
34 (* blocks of (co)inductive definitions and constants) and the terms of cic   *)
35 (*                                                                           *)
36 (*****************************************************************************)
37
38 (* $Id$ *)
39
40 (* STUFF TO MANAGE IDENTIFIERS *)
41 type id = string  (* the abstract type of the (annotated) node identifiers *)
42 type 'term explicit_named_substitution = (UriManager.uri * 'term) list
43
44 type implicit_annotation = [ `Closed | `Type | `Hole ]
45
46 (* INTERNAL REPRESENTATION OF CIC OBJECTS AND TERMS *)
47
48 type sort =
49    Prop
50  | Set
51  | Type of CicUniv.universe
52  | CProp of CicUniv.universe
53
54 type name =
55  | Name of string
56  | Anonymous
57
58 type object_flavour =
59   [ `Definition
60   | `MutualDefinition
61   | `Fact
62   | `Lemma
63   | `Remark
64   | `Theorem
65   | `Variant
66   | `Axiom
67   ]
68
69 type object_class =
70   [ `Elim of sort   (** elimination principle; if sort is Type, the universe is
71                       * not relevant *)
72   | `Record of (string * bool * int) list (** 
73                         inductive type that encodes a record; the arguments are
74                         the record fields names and if they are coercions and
75                         then the coercion arity *)
76   | `Projection     (** record projection *)
77   | `InversionPrinciple (** inversion principle *)
78   ]
79
80 type attribute =
81   [ `Class of object_class
82   | `Flavour of object_flavour 
83   | `Generated
84   ]
85
86 type term =
87    Rel of int                                       (* DeBrujin index, 1 based*)
88  | Var of UriManager.uri *                          (* uri,                   *)
89      term explicit_named_substitution               (*  explicit named subst. *)
90  | Meta of int * (term option) list                 (* numeric id,    *)
91                                                     (*  local context *)
92  | Sort of sort                                     (* sort *)
93  | Implicit of implicit_annotation option           (* *)
94  | Cast of term * term                              (* value, type *)
95  | Prod of name * term * term                       (* binder, source, target *)
96  | Lambda of name * term * term                     (* binder, source, target *)
97  | LetIn of name * term * term * term               (* binder, term, type, target *)
98  | Appl of term list                                (* arguments *)
99  | Const of UriManager.uri *                        (* uri,                   *)
100      term explicit_named_substitution               (*  explicit named subst. *)
101  | MutInd of UriManager.uri * int *                 (* uri, typeno, *)
102      term explicit_named_substitution               (*  explicit named subst. *)
103                                                     (* typeno is 0 based      *)
104  | MutConstruct of UriManager.uri *                 (* uri,                   *)
105     int * int *                                     (*  typeno, consno        *)
106      term explicit_named_substitution               (*  explicit named subst. *)
107                                                     (* typeno is 0 based      *)
108                                                     (* consno is 1 based      *)
109  | MutCase of UriManager.uri *                      (* ind. uri,             *)
110     int *                                           (*  ind. typeno,         *)
111     term * term *                                   (*  outtype, ind. term   *)
112     term list                                       (*  patterns             *)
113  | Fix of int * inductiveFun list                   (* funno (0 based), funs *)
114  | CoFix of int * coInductiveFun list               (* funno (0 based), funs *)
115 and obj =
116    Constant of string * term option * term *      (* id, body, type,          *)
117     UriManager.uri list * attribute list          (*  parameters              *)
118  | Variable of string * term option * term *      (* name, body, type         *)
119     UriManager.uri list * attribute list          (* parameters               *)
120  | CurrentProof of string * metasenv * term *     (* name, conjectures, body, *)
121     term * UriManager.uri list * attribute list   (*  type, parameters        *)
122  | InductiveDefinition of inductiveType list *    (* inductive types,         *)
123     UriManager.uri list * int * attribute list    (*  params, left params no  *)
124 and inductiveType = 
125  string * bool * term *                       (* typename, inductive, arity *)
126   constructor list                            (*  constructors              *)
127 and constructor =
128  string * term                                (* id, type *)
129 and inductiveFun =
130  string * int * term * term                   (* name, ind. index, type, body *)
131 and coInductiveFun =
132  string * term * term                         (* name, type, body *)
133
134 (* a metasenv is a list of declarations of metas in declarations *)
135 (* order (i.e. [oldest ; ... ; newest]). Older variables can not *)
136 (* depend on new ones.                                           *)
137 and conjecture = int * context * term
138 and metasenv = conjecture list
139 and substitution = (int * (context * term * term)) list
140
141
142
143 (* a metasenv is a list of declarations of metas in declarations *)
144 (* order (i.e. [oldest ; ... ; newest]). Older variables can not *)
145 (* depend on new ones.                                           *)
146 and annconjecture = id * int * anncontext * annterm
147 and annmetasenv = annconjecture list
148
149 and annterm =
150    ARel of id * id * int *                          (* idref, DeBrujin index, *)
151     string                                          (*  binder                *)
152  | AVar of id * UriManager.uri *                    (* uri,                   *)
153     annterm explicit_named_substitution             (*  explicit named subst. *)
154  | AMeta of id * int * (annterm option) list        (* numeric id,    *)
155                                                     (*  local context *)
156  | ASort of id * sort                               (* sort *)
157  | AImplicit of id * implicit_annotation option     (* *)
158  | ACast of id * annterm * annterm                  (* value, type *)
159  | AProd of id * name * annterm * annterm           (* binder, source, target *)
160  | ALambda of id * name * annterm * annterm         (* binder, source, target *)
161  | ALetIn of id * name * annterm * annterm *  annterm (* binder, term, type, target *)
162  | AAppl of id * annterm list                       (* arguments *)
163  | AConst of id * UriManager.uri *                  (* uri,                   *)
164     annterm explicit_named_substitution             (*  explicit named subst. *)
165  | AMutInd of id * UriManager.uri * int *           (* uri, typeno            *)
166     annterm explicit_named_substitution             (*  explicit named subst. *)
167                                                     (* typeno is 0 based *)
168  | AMutConstruct of id * UriManager.uri *           (* uri,                   *)
169     int * int *                                     (*  typeno, consno        *)
170     annterm explicit_named_substitution             (*  explicit named subst. *)
171                                                     (* typeno is 0 based *)
172                                                     (* consno is 1 based *)
173  | AMutCase of id * UriManager.uri *                (* ind. uri,             *)
174     int *                                           (*  ind. typeno,         *)
175     annterm * annterm *                             (*  outtype, ind. term   *)
176     annterm list                                    (*  patterns             *)
177  | AFix of id * int * anninductiveFun list          (* funno, functions *)
178  | ACoFix of id * int * anncoInductiveFun list      (* funno, functions *)
179 and annobj =
180    AConstant of id * id option * string *           (* name,         *)
181     annterm option * annterm *                      (*  body, type,  *)
182     UriManager.uri list * attribute list            (*  parameters   *)
183  | AVariable of id *
184     string * annterm option * annterm *             (* name, body, type *)
185     UriManager.uri list * attribute list            (*  parameters      *)
186  | ACurrentProof of id * id *
187     string * annmetasenv *                          (*  name, conjectures,    *)
188     annterm * annterm * UriManager.uri list *       (*  body,type,parameters  *)
189     attribute list
190  | AInductiveDefinition of id *
191     anninductiveType list *                         (* inductive types ,      *)
192     UriManager.uri list * int * attribute list      (*  parameters,n ind. pars*)
193 and anninductiveType = 
194  id * string * bool * annterm *               (* typename, inductive, arity *)
195   annconstructor list                         (*  constructors              *)
196 and annconstructor =
197  string * annterm                             (* id, type *)
198 and anninductiveFun =
199  id * string * int * annterm * annterm        (* name, ind. index, type, body *)
200 and anncoInductiveFun =
201  id * string * annterm * annterm              (* name, type, body *)
202 and annotation =
203  string
204
205 and context_entry =                            (* A declaration or definition *)
206    Decl of term
207  | Def of term * term                          (* body, type *)
208
209 and hypothesis =
210  (name * context_entry) option               (* None means no more accessible *)
211
212 and context = hypothesis list
213
214 and anncontext_entry =                         (* A declaration or definition *)
215    ADecl of annterm
216  | ADef of annterm * annterm
217
218 and annhypothesis =
219  id * (name * anncontext_entry) option       (* None means no more accessible *)
220
221 and anncontext = annhypothesis list
222 ;;
223
224 type lazy_term =
225  context -> metasenv -> CicUniv.universe_graph ->
226   term * metasenv * CicUniv.universe_graph
227
228 type anntarget =
229    Object of annobj         (* if annobj is a Constant, this is its type *)
230  | ConstantBody of annobj
231  | Term of annterm
232  | Conjecture of annconjecture
233  | Hypothesis of annhypothesis
234
235 module CicHash =
236  Hashtbl.Make
237   (struct
238     type t = term
239     let equal = (==)
240     let hash = Hashtbl.hash_param 100 1000 
241    end)
242 ;;
243