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