feat(frontends/lean/inductive_cmd): improve notation for declaring 'empty' inductive datatypes

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-25 11:24:01 -07:00
parent a5b9a7b296
commit a450ad5a95
3 changed files with 15 additions and 9 deletions

View file

@ -152,8 +152,7 @@ notation `Ω` `(` A `,` a `)` := loop_space A a
definition loop2d_space (A : Type) (a : A) := (refl a) = (refl a) definition loop2d_space (A : Type) (a : A) := (refl a) = (refl a)
notation `Ω²` `(` A `,` a `)` := loop2d_space A a notation `Ω²` `(` A `,` a `)` := loop2d_space A a
inductive empty : Type := inductive empty : Type
-- empty
theorem empty_elim (c : Type) (H : empty) : c theorem empty_elim (c : Type) (H : empty) : c
:= empty_rec (λ e, c) H := empty_rec (λ e, c) H

View file

@ -3,8 +3,7 @@
-- Authors: Leonardo de Moura, Jeremy Avigad -- Authors: Leonardo de Moura, Jeremy Avigad
definition Prop [inline] := Type.{0} definition Prop [inline] := Type.{0}
inductive false : Prop := inductive false : Prop
-- No constructors
theorem false_elim (c : Prop) (H : false) : c theorem false_elim (c : Prop) (H : false) : c
:= false_rec c H := false_rec c H

View file

@ -279,17 +279,25 @@ struct inductive_cmd_fn {
name d_name = parse_decl_name(); name d_name = parse_decl_name();
parse_inductive_univ_params(); parse_inductive_univ_params();
expr d_type = parse_datatype_type(); expr d_type = parse_datatype_type();
m_p.check_token_next(g_assign, "invalid inductive declaration, ':=' expected"); bool empty_type = true;
if (m_p.curr_is_token(g_assign)) {
empty_type = false;
m_p.next();
}
level_param_names d_lvls; level_param_names d_lvls;
std::tie(d_type, d_lvls) = elaborate_inductive_type(d_type); std::tie(d_type, d_lvls) = elaborate_inductive_type(d_type);
if (!m_first) { if (!m_first) {
check_params(d_type, *first_d_type); check_params(d_type, *first_d_type);
check_levels(d_lvls, *first_d_lvls); check_levels(d_lvls, *first_d_lvls);
} }
buffer<expr> params; if (empty_type) {
add_params_to_local_scope(d_type, params); decls.push_back(inductive_decl(d_name, d_type, list<intro_rule>()));
auto d_intro_rules = parse_intro_rules(params); } else {
decls.push_back(inductive_decl(d_name, d_type, d_intro_rules)); buffer<expr> params;
add_params_to_local_scope(d_type, params);
auto d_intro_rules = parse_intro_rules(params);
decls.push_back(inductive_decl(d_name, d_type, d_intro_rules));
}
if (!m_p.curr_is_token(g_with)) { if (!m_p.curr_is_token(g_with)) {
m_levels.append(m_explict_levels); m_levels.append(m_explict_levels);
for (auto l : d_lvls) m_levels.push_back(l); for (auto l : d_lvls) m_levels.push_back(l);