]> matita.cs.unibo.it Git - helm.git/blob - components/cic/cic.ml
BIG FAT COMMIT REGARDING COERCIONS:
[helm.git] / 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
53
54 type name =
55  | Name of string
56  | Anonymous
57
58 type object_flavour =
59   [ `Definition
60   | `Fact
61   | `Lemma
62   | `Remark
63   | `Theorem
64   | `Variant
65   | `Axiom
66   ]
67
68 type object_class =
69   [ `Coercion of int
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   ]
78
79 type attribute =
80   [ `Class of object_class
81   | `Flavour of object_flavour 
82   | `Generated
83   ]
84
85 type term =
86    Rel of int                                       (* DeBrujin index, 1 based*)
87  | Var of UriManager.uri *                          (* uri,                   *)
88      term explicit_named_substitution               (*  explicit named subst. *)
89  | Meta of int * (term option) list                 (* numeric id,    *)
90                                                     (*  local context *)
91  | Sort of sort                                     (* sort *)
92  | Implicit of implicit_annotation option           (* *)
93  | Cast of term * term                              (* value, type *)
94  | Prod of name * term * term                       (* binder, source, target *)
95  | Lambda of name * term * term                     (* binder, source, target *)
96  | LetIn of name * term * term                      (* binder, term, target *)
97  | Appl of term list                                (* arguments *)
98  | Const of UriManager.uri *                        (* uri,                   *)
99      term explicit_named_substitution               (*  explicit named subst. *)
100  | MutInd of UriManager.uri * int *                 (* uri, typeno, *)
101      term explicit_named_substitution               (*  explicit named subst. *)
102                                                     (* typeno is 0 based      *)
103  | MutConstruct of UriManager.uri *                 (* uri,                   *)
104     int * int *                                     (*  typeno, consno        *)
105      term explicit_named_substitution               (*  explicit named subst. *)
106                                                     (* typeno is 0 based      *)
107                                                     (* consno is 1 based      *)
108  | MutCase of UriManager.uri *                      (* ind. uri,             *)
109     int *                                           (*  ind. typeno,         *)
110     term * term *                                   (*  outtype, ind. term   *)
111     term list                                       (*  patterns             *)
112  | Fix of int * inductiveFun list                   (* funno (0 based), funs *)
113  | CoFix of int * coInductiveFun list               (* funno (0 based), funs *)
114 and obj =
115    Constant of string * term option * term *      (* id, body, type,          *)
116     UriManager.uri list * attribute list          (*  parameters              *)
117  | Variable of string * term option * term *      (* name, body, type         *)
118     UriManager.uri list * attribute list          (* parameters               *)
119  | CurrentProof of string * metasenv * term *     (* name, conjectures, body, *)
120     term * UriManager.uri list * attribute list   (*  type, parameters        *)
121  | InductiveDefinition of inductiveType list *    (* inductive types,         *)
122     UriManager.uri list * int * attribute list    (*  params, left params no  *)
123 and inductiveType = 
124  string * bool * term *                       (* typename, inductive, arity *)
125   constructor list                            (*  constructors              *)
126 and constructor =
127  string * term                                (* id, type *)
128 and inductiveFun =
129  string * int * term * term                   (* name, ind. index, type, body *)
130 and coInductiveFun =
131  string * term * term                         (* name, type, body *)
132
133 (* a metasenv is a list of declarations of metas in declarations *)
134 (* order (i.e. [oldest ; ... ; newest]). Older variables can not *)
135 (* depend on new ones.                                           *)
136 and conjecture = int * context * term
137 and metasenv = conjecture list
138 and substitution = (int * (context * term * term)) list
139
140
141
142 (* a metasenv is a list of declarations of metas in declarations *)
143 (* order (i.e. [oldest ; ... ; newest]). Older variables can not *)
144 (* depend on new ones.                                           *)
145 and annconjecture = id * int * anncontext * annterm
146 and annmetasenv = annconjecture list
147
148 and annterm =
149    ARel of id * id * int *                          (* idref, DeBrujin index, *)
150     string                                          (*  binder                *)
151  | AVar of id * UriManager.uri *                    (* uri,                   *)
152     annterm explicit_named_substitution             (*  explicit named subst. *)
153  | AMeta of id * int * (annterm option) list        (* numeric id,    *)
154                                                     (*  local context *)
155  | ASort of id * sort                               (* sort *)
156  | AImplicit of id * implicit_annotation option     (* *)
157  | ACast of id * annterm * annterm                  (* value, type *)
158  | AProd of id * name * annterm * annterm           (* binder, source, target *)
159  | ALambda of id * name * annterm * annterm         (* binder, source, target *)
160  | ALetIn of id * name * annterm * annterm          (* binder, term, target *)
161  | AAppl of id * annterm list                       (* arguments *)
162  | AConst of id * UriManager.uri *                  (* uri,                   *)
163     annterm explicit_named_substitution             (*  explicit named subst. *)
164  | AMutInd of id * UriManager.uri * int *           (* uri, typeno            *)
165     annterm explicit_named_substitution             (*  explicit named subst. *)
166                                                     (* typeno is 0 based *)
167  | AMutConstruct of id * UriManager.uri *           (* uri,                   *)
168     int * int *                                     (*  typeno, consno        *)
169     annterm explicit_named_substitution             (*  explicit named subst. *)
170                                                     (* typeno is 0 based *)
171                                                     (* consno is 1 based *)
172  | AMutCase of id * UriManager.uri *                (* ind. uri,             *)
173     int *                                           (*  ind. typeno,         *)
174     annterm * annterm *                             (*  outtype, ind. term   *)
175     annterm list                                    (*  patterns             *)
176  | AFix of id * int * anninductiveFun list          (* funno, functions *)
177  | ACoFix of id * int * anncoInductiveFun list      (* funno, functions *)
178 and annobj =
179    AConstant of id * id option * string *           (* name,         *)
180     annterm option * annterm *                      (*  body, type,  *)
181     UriManager.uri list * attribute list            (*  parameters   *)
182  | AVariable of id *
183     string * annterm option * annterm *             (* name, body, type *)
184     UriManager.uri list * attribute list            (*  parameters      *)
185  | ACurrentProof of id * id *
186     string * annmetasenv *                          (*  name, conjectures,    *)
187     annterm * annterm * UriManager.uri list *       (*  body,type,parameters  *)
188     attribute list
189  | AInductiveDefinition of id *
190     anninductiveType list *                         (* inductive types ,      *)
191     UriManager.uri list * int * attribute list      (*  parameters,n ind. pars*)
192 and anninductiveType = 
193  id * string * bool * annterm *               (* typename, inductive, arity *)
194   annconstructor list                         (*  constructors              *)
195 and annconstructor =
196  string * annterm                             (* id, type *)
197 and anninductiveFun =
198  id * string * int * annterm * annterm        (* name, ind. index, type, body *)
199 and anncoInductiveFun =
200  id * string * annterm * annterm              (* name, type, body *)
201 and annotation =
202  string
203
204 and context_entry =                            (* A declaration or definition *)
205    Decl of term
206  | Def of term * term option                   (* body, type (if known) *)
207
208 and hypothesis =
209  (name * context_entry) option               (* None means no more accessible *)
210
211 and context = hypothesis list
212
213 and anncontext_entry =                         (* A declaration or definition *)
214    ADecl of annterm
215  | ADef of annterm
216
217 and annhypothesis =
218  id * (name * anncontext_entry) option       (* None means no more accessible *)
219
220 and anncontext = annhypothesis list
221 ;;
222
223 type lazy_term =
224  context -> metasenv -> CicUniv.universe_graph ->
225   term * metasenv * CicUniv.universe_graph
226
227 type anntarget =
228    Object of annobj         (* if annobj is a Constant, this is its type *)
229  | ConstantBody of annobj
230  | Term of annterm
231  | Conjecture of annconjecture
232  | Hypothesis of annhypothesis
233
234 module CicHash =
235  Hashtbl.Make
236   (struct
237     type t = term
238     let equal = (==)
239     let hash = Hashtbl.hash_param 100 1000 
240    end)
241 ;;
242