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