feat(library/export, doc/export_format): remove support for mutually inductive types

This commit is contained in:
Daniel Selsam 2016-03-10 20:07:09 -08:00
parent 0c4a6d3c5e
commit 8f0a0d2b32
2 changed files with 57 additions and 84 deletions

View file

@ -197,78 +197,47 @@ The following command declare the `definition id.{l} {A : Type.{l}} (a : A) : A
Inductive definitions Inductive definitions
--------------------- ---------------------
Mutually inductive datatype declarations are slightly more complicated. Inductive datatype declarations have the following form:
They are declared by a block of commands delimited by the command `#BIND` and `#EIND`.
The command `#BIND` has the following form:
``` ```
#BIND <integer> <integer> <nidx>* #IND <name:nidx> <numParams:integer> <lpNames:nidx>* | <type:eidx> <numIntroRules:integer>
#IR <irName:nidx> <irType:eidx>
...
#IR <irName:nidx> <irType:eidx>
``` ```
where the first integer are the number of parameters, the second is the number of For example, the following inductive type declaration
mutually recursive types being declared by the block, and `nidx*` is the sequence
of universe parameter _names_.
The command `#EIND` is just a delimiter and does not have arguments.
The block is composed by commands `#IND` and `#INTRO`.
```
#IND <nidx> <eidx>
#INTRO <nidx> <eidx>
```
The command `#IND` declares an inductive type with name `nidx` and type `eidx`.
The command `#INTRO` declares an introduction rule (aka constructor) with name
`nidx` and type `eidx`. The first command in a block is always an `#IND`,
the subsequent `#INTRO` commands are declaring the introduction rules for this
inductive type.
For example, the following mutually recursive declaration
```lean ```lean
inductive tree.{l} (A : Type.{l}) : Type.{max 1 l} := inductive list.{l} (T : Type.{l}) : Type.{max 1 l} :=
| node : tree_list.{l} A → tree.{l} A | nil : list.{l} T
| empty : tree.{l} A | cons : T → list.{l} T → list.{l} T
with tree_list : Type.{max 1 l} :=
| nil : tree_list.{l} A
| cons : tree.{l} A → tree_list.{l} A → tree_list.{l} A
``` ```
is encoded by the following sequence of commands is encoded by the following sequence of commands:
``` ```
2 #NS 0 l 2 #NS 0 l
3 #NS 0 tree 3 #NS 0 list
4 #NS 0 A 4 #NS 0 T
1 #UP 2 1 #UP 2
0 #ES 1 0 #ES 1
2 #US 0 2 #US 0
3 #UM 2 1 3 #UM 2 1
1 #ES 3 1 #ES 3
2 #EP #D 4 0 1 2 #EP #BD 4 0 1
5 #NS 3 node 5 #NS 3 nil
6 #NS 0 a 3 #EC 3 1
7 #NS 0 tree_list
3 #EC 7 1
4 #EV 0 4 #EV 0
5 #EA 3 4 5 #EA 3 4
6 #EC 3 1 6 #EP #BD 4 0 5
6 #NS 3 cons
7 #NS 0 a
7 #EV 1 7 #EV 1
8 #EA 6 7 8 #EA 3 7
9 #EP #BD 6 5 8 9 #EV 2
10 #EP #BI 4 0 9 10 #EA 3 9
8 #NS 3 empty 11 #EP #BD 7 8 10
11 #EA 6 4 12 #EP #BD 7 4 11
12 #EP #BD 4 0 11 13 #EP #BI 4 0 12
9 #NS 7 nil #IND 1 2 | 3 2 2
13 #EP #BD 4 0 5 #INTRO 5 6
10 #NS 7 cons #INTRO 6 13
14 #EA 3 7
15 #EV 2
16 #EA 3 15
17 #EP #BD 6 14 16
18 #EP #BD 6 11 17
19 #EP #BI 4 0 18
#BIND 1 2 2
#IND 3 2
#INTRO 5 10
#INTRO 8 12
#IND 7 2
#INTRO 9 13
#INTRO 10 19
#EIND
``` ```
Exporting declarations Exporting declarations

View file

@ -238,39 +238,43 @@ class exporter {
if (already_exported(n)) if (already_exported(n))
return; return;
mark(n); mark(n);
std::tuple<level_param_names, unsigned, list<inductive::inductive_decl>> decls = level_param_names lp_names; unsigned num_params; list<inductive::inductive_decl> idecls;
*inductive::is_inductive_decl(m_env, n); std::tie(lp_names, num_params, idecls) = *inductive::is_inductive_decl(m_env, n);
lean_assert(length(idecls) == 1);
inductive::inductive_decl idecl = head(idecls);
if (m_all) { if (m_all) {
for (inductive::inductive_decl const & d : std::get<2>(decls)) { export_dependencies(inductive::inductive_decl_type(idecl));
export_dependencies(inductive::inductive_decl_type(d)); for (inductive::intro_rule const & c : inductive::inductive_decl_intros(idecl)) {
for (inductive::intro_rule const & c : inductive::inductive_decl_intros(d)) { export_dependencies(inductive::intro_rule_type(c));
export_dependencies(inductive::intro_rule_type(c));
}
} }
} }
for (name const & p : std::get<0>(decls)) for (name const & p : lp_names) {
export_name(p); export_name(p);
for (inductive::inductive_decl const & d : std::get<2>(decls)) {
export_name(inductive::inductive_decl_name(d));
export_root_expr(inductive::inductive_decl_type(d));
for (inductive::intro_rule const & c : inductive::inductive_decl_intros(d)) {
export_name(inductive::intro_rule_name(c));
export_root_expr(inductive::intro_rule_type(c));
}
} }
m_out << "#BIND " << std::get<1>(decls) << " " << length(std::get<2>(decls)); export_name(inductive::inductive_decl_name(idecl));
for (name const & p : std::get<0>(decls)) export_root_expr(inductive::inductive_decl_type(idecl));
for (inductive::intro_rule const & c : inductive::inductive_decl_intros(idecl)) {
export_name(inductive::intro_rule_name(c));
export_root_expr(inductive::intro_rule_type(c));
}
m_out << "#IND"
<< " " << num_params;
for (name const & p : lp_names)
m_out << " " << export_name(p); m_out << " " << export_name(p);
m_out << "\n";
for (inductive::inductive_decl const & d : std::get<2>(decls)) { m_out << " |"
m_out << "#IND " << export_name(inductive::inductive_decl_name(d)) << " " << " " << export_name(inductive::inductive_decl_name(idecl))
<< export_root_expr(inductive::inductive_decl_type(d)) << "\n"; << " " << export_root_expr(inductive::inductive_decl_type(idecl))
for (inductive::intro_rule const & c : inductive::inductive_decl_intros(d)) { << " " << length(inductive::inductive_decl_intros(idecl))
m_out << "#INTRO " << export_name(inductive::intro_rule_name(c)) << " " << "\n";
<< export_root_expr(inductive::intro_rule_type(c)) << "\n";
} for (inductive::intro_rule const & c : inductive::inductive_decl_intros(idecl)) {
m_out << "#INTRO"
<< " " << export_name(inductive::intro_rule_name(c))
<< " " << export_root_expr(inductive::intro_rule_type(c))
<< "\n";
} }
m_out << "#EIND\n";
} }
void export_declaration(name const & n) { void export_declaration(name const & n) {