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