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