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