feat(frontends/lean): remove [class] annotation and 'class' command, they are redundant, we only need [instance] and 'instance'

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-07 16:09:30 -07:00
parent 112353861c
commit 08465f049a
8 changed files with 7 additions and 62 deletions

View file

@ -209,8 +209,6 @@ theorem exists_unique_elim {A : Type} {p : A → Bool} {b : Bool} (H2 : ∃! x,
inductive inhabited (A : Type) : Bool :=
| inhabited_intro : A → inhabited A
class inhabited
theorem inhabited_elim {A : Type} {B : Bool} (H1 : inhabited A) (H2 : A → B) : B
:= inhabited_rec H2 H1

View file

@ -12,22 +12,15 @@ Author: Leonardo de Moura
namespace lean {
struct class_entry {
enum class kind { NewClass, NewInstance };
kind m_kind;
name m_class;
name m_instance;
class_entry() {}
class_entry(name const & c):m_kind(kind::NewClass), m_class(c) {}
class_entry(name const & c, name const & i):m_kind(kind::NewInstance), m_class(c), m_instance(i) {}
bool is_new_class() const { return m_kind == kind::NewClass; }
class_entry(name const & c, name const & i):m_class(c), m_instance(i) {}
};
struct class_state {
typedef rb_map<name, list<name>, name_quick_cmp> class_instances;
class_instances m_instances;
void add_class(name const & c) {
m_instances.insert(c, list<name>());
}
void add_instance(name const & c, name const & i) {
auto it = m_instances.find(c);
if (!it)
@ -41,11 +34,7 @@ struct class_config {
typedef class_state state;
typedef class_entry entry;
static void add_entry(environment const &, io_state const &, state & s, entry const & e) {
if (e.m_kind == class_entry::kind::NewClass) {
s.add_class(e.m_class);
} else {
s.add_instance(e.m_class, e.m_instance);
}
s.add_instance(e.m_class, e.m_instance);
}
static name const & get_class_name() {
static name g_class_name("class");
@ -56,19 +45,11 @@ struct class_config {
return g_key;
}
static void write_entry(serializer & s, entry const & e) {
s.write_char(static_cast<char>(e.m_kind)); // NOLINT
if (e.is_new_class())
s << e.m_class;
else
s << e.m_class << e.m_instance;
s << e.m_class << e.m_instance;
}
static entry read_entry(deserializer & d) {
entry e;
e.m_kind = static_cast<class_entry::kind>(d.read_char());
if (e.is_new_class())
d >> e.m_class;
else
d >> e.m_class >> e.m_instance;
d >> e.m_class >> e.m_instance;
return e;
}
};
@ -76,16 +57,6 @@ struct class_config {
template class scoped_ext<class_config>;
typedef scoped_ext<class_config> class_ext;
environment add_class(environment const & env, name const & n) {
declaration d = env.get(n);
if (d.is_definition() && !d.is_opaque())
throw exception(sstream() << "invalid class declaration, '" << n << "' is not an opaque definition");
class_state const & s = class_ext::get_state(env);
if (s.m_instances.contains(n))
throw exception(sstream() << "class '" << n << "' has already been declared");
return class_ext::add_entry(env, get_dummy_ios(), class_entry(n));
}
environment add_instance(environment const & env, name const & n) {
declaration d = env.get(n);
expr type = d.get_type();
@ -94,6 +65,9 @@ environment add_instance(environment const & env, name const & n) {
if (!is_constant(get_app_fn(type)))
throw exception(sstream() << "invalid class instance declaration '" << n << "' resultant type must be a class");
name const & c = const_name(get_app_fn(type));
declaration c_d = env.get(c);
if (c_d.is_definition() && !c_d.is_opaque())
throw exception(sstream() << "invalid class instance declaration, '" << c << "' is not a valid class, it is a transparent definition");
return class_ext::add_entry(env, get_dummy_ios(), class_entry(c, n));
}
@ -110,14 +84,6 @@ list<name> get_class_instances(environment const & env, name const & c) {
return list<name>();
}
environment add_class_cmd(parser & p) {
auto pos = p.pos();
name c = p.check_id_next("invalid 'class' declaration, identifier expected");
expr e = p.id_to_expr(c, pos);
if (!is_constant(e)) throw parser_error(sstream() << "invalid 'class' declaration, '" << c << "' is not a constant", pos);
return add_class(p.env(), const_name(e));
}
environment add_instance_cmd(parser & p) {
bool found = false;
environment env = p.env();
@ -136,7 +102,6 @@ environment add_instance_cmd(parser & p) {
}
void register_class_cmds(cmd_table & r) {
add_cmd(r, cmd_info("class", "add a new class", add_class_cmd));
add_cmd(r, cmd_info("instance", "add a new instance", add_instance_cmd));
}
}

View file

@ -11,8 +11,6 @@ Author: Leonardo de Moura
#include "frontends/lean/cmd_table.h"
namespace lean {
/** \brief Add a new 'class' to the environment. */
environment add_class(environment const & env, name const & n);
/** \brief Add a new 'class instance' to the environment. */
environment add_instance(environment const & env, name const & n);
/** \brief Return true iff \c c was declared with \c add_class . */

View file

@ -25,7 +25,6 @@ static name g_assign(":=");
static name g_private("[private]");
static name g_inline("[inline]");
static name g_instance("[instance]");
static name g_class("[class]");
environment universe_cmd(parser & p) {
name n = p.check_id_next("invalid universe declaration, identifier expected");
@ -168,12 +167,10 @@ struct decl_modifiers {
bool m_is_private;
bool m_is_opaque;
bool m_is_instance;
bool m_is_class;
decl_modifiers() {
m_is_private = false;
m_is_opaque = true;
m_is_instance = false;
m_is_class = false;
}
void parse(parser & p) {
@ -187,9 +184,6 @@ struct decl_modifiers {
} else if (p.curr_is_token(g_instance)) {
m_is_instance = true;
p.next();
} else if (p.curr_is_token(g_class)) {
m_is_class = true;
p.next();
} else {
break;
}
@ -285,8 +279,6 @@ environment definition_cmd_core(parser & p, bool is_theorem, bool _is_opaque) {
std::tie(type, value, new_ls) = p.elaborate_definition(n, type, value);
env = module::add(env, check(env, mk_definition(env, real_n, append(ls, new_ls), type, value, modifiers.m_is_opaque)));
}
if (modifiers.m_is_class)
env = add_class(env, real_n);
if (modifiers.m_is_instance)
env = add_instance(env, real_n);
return env;

View file

@ -59,8 +59,6 @@ inductive not_zero (x : nat) : Bool :=
theorem not_zero_not_is_zero {x : nat} (H : not_zero x) : ¬ is_zero x
:= not_zero_rec (λ H1, H1) H
class not_zero
theorem not_zero_add_right [instance] (x y : nat) (H : not_zero y) : not_zero (x + y)
:= not_zero_intro (not_zero_add x y (not_zero_not_is_zero H))

View file

@ -4,8 +4,6 @@ namespace algebra
inductive mul_struct (A : Type) : Type :=
| mk_mul_struct : (A → A → A) → mul_struct A
class mul_struct
definition mul [inline] {A : Type} {s : mul_struct A} (a b : A)
:= mul_struct_rec (λ f, f) s a b

View file

@ -16,8 +16,6 @@ end
inductive group_struct (A : Type) : Type :=
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
class group_struct
inductive group : Type :=
| mk_group : Π (A : Type), group_struct A → group

View file

@ -16,8 +16,6 @@ end
inductive group_struct (A : Type) : Type :=
| mk_group_struct : Π (mul : A → A → A) (one : A) (inv : A → A), is_assoc mul → is_id mul one → is_inv mul one inv → group_struct A
class group_struct
inductive group : Type :=
| mk_group : Π (A : Type), group_struct A → group