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