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