refactor(library/init/core,library/init/unit): make unit an abbreviation of punit.{0}

This commit is contained in:
Sebastian Ullrich 2018-03-26 18:38:47 +02:00 committed by Leonardo de Moura
parent efa9d7e110
commit 3fefe94757
12 changed files with 43 additions and 41 deletions

View file

@ -243,6 +243,8 @@ master branch (aka work in progress branch)
* The monad laws have been separated into new type classes `is_lawful_{functor,applicative,monad}`.
* `unit` is now an abbreviation of `punit.{0}`
*API name changes*
* `monad.has_monad_lift(_t)` ~> `has_monad_lift(_t)`
@ -251,6 +253,7 @@ master branch (aka work in progress branch)
* deleted `monad.monad_transformer`
* deleted `monad.lift{n}`. Use `f <$> a1 <*> ... <*> an` instead of `monad.lift{n} f a1 ... an`.
* merged `has_map` into `functor`
* `unit_eq(_unit)` ~> `punit_eq(_punit)`
v3.3.0 (14 September 2017)
-------------

View file

@ -113,8 +113,12 @@ abbreviation id_rhs (α : Sort u) (a : α) : α := a
inductive punit : Sort u
| star : punit
inductive unit : Type
| star : unit
/-- An abbreviation for `punit.{0}`, its most common instantiation.
This type should be preferred over `punit` where possible to avoid
unnecessary universe parameters. -/
abbreviation unit : Type := punit
@[pattern] abbreviation unit.star : unit := punit.star
/--
Gadget for defining thunks, thunk parameters have special treatment.
@ -491,11 +495,6 @@ protected def psigma.sizeof {α : Type u} {β : α → Type v} [has_sizeof α] [
instance (α : Type u) (β : α → Type v) [has_sizeof α] [∀ a, has_sizeof (β a)] : has_sizeof (psigma β) :=
⟨psigma.sizeof⟩
protected def unit.sizeof : unit → nat
| u := 1
instance : has_sizeof unit := ⟨unit.sizeof⟩
protected def punit.sizeof : punit → nat
| u := 1

View file

@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.setoid init.data.quot init.data.bool.basic init.data.unit
import init.data.setoid init.data.quot init.data.bool.basic init.data.punit
import init.data.nat.basic init.data.prod init.data.sum.basic
import init.data.sigma.basic init.data.subtype.basic
import init.data.fin.basic init.data.list.basic init.data.char.basic

View file

@ -0,0 +1,22 @@
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.logic
lemma punit_eq (a b : punit) : a = b :=
punit.rec_on a (punit.rec_on b rfl)
lemma punit_eq_punit (a : punit) : a = () :=
punit_eq a ()
instance : subsingleton punit :=
subsingleton.intro punit_eq
instance : inhabited punit :=
⟨()⟩
instance : decidable_eq punit :=
λ a b, is_true (punit_eq a b)

View file

@ -1,22 +0,0 @@
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
prelude
import init.logic
lemma unit_eq (a b : unit) : a = b :=
unit.rec_on a (unit.rec_on b rfl)
lemma unit_eq_unit (a : unit) : a = () :=
unit_eq a ()
instance : subsingleton unit :=
subsingleton.intro unit_eq
instance : inhabited unit :=
⟨()⟩
instance : decidable_eq unit :=
λ a b, is_true (unit_eq a b)

View file

@ -34,6 +34,5 @@ meta instance list.reflect {α : Type} [has_reflect α] [reflected α] : has_ref
| [] := `([])
| (h::t) := `(λ t, h :: t).subst (list.reflect t)
meta instance unit.reflect : has_reflect unit
meta instance punit.reflect : has_reflect punit
| () := `(_)

View file

@ -286,6 +286,7 @@ name const * g_opt_param = nullptr;
name const * g_or = nullptr;
name const * g_out_param = nullptr;
name const * g_punit = nullptr;
name const * g_punit_cases_on = nullptr;
name const * g_punit_star = nullptr;
name const * g_prod_mk = nullptr;
name const * g_pprod = nullptr;
@ -343,7 +344,6 @@ name const * g_true_intro = nullptr;
name const * g_unification_hint = nullptr;
name const * g_unification_hint_mk = nullptr;
name const * g_unit = nullptr;
name const * g_unit_cases_on = nullptr;
name const * g_unit_star = nullptr;
name const * g_monad_from_pure_bind = nullptr;
name const * g_user_attribute = nullptr;
@ -643,6 +643,7 @@ void initialize_constants() {
g_or = new name{"or"};
g_out_param = new name{"out_param"};
g_punit = new name{"punit"};
g_punit_cases_on = new name{"punit", "cases_on"};
g_punit_star = new name{"punit", "star"};
g_prod_mk = new name{"prod", "mk"};
g_pprod = new name{"pprod"};
@ -700,7 +701,6 @@ void initialize_constants() {
g_unification_hint = new name{"unification_hint"};
g_unification_hint_mk = new name{"unification_hint", "mk"};
g_unit = new name{"unit"};
g_unit_cases_on = new name{"unit", "cases_on"};
g_unit_star = new name{"unit", "star"};
g_monad_from_pure_bind = new name{"monad_from_pure_bind"};
g_user_attribute = new name{"user_attribute"};
@ -1001,6 +1001,7 @@ void finalize_constants() {
delete g_or;
delete g_out_param;
delete g_punit;
delete g_punit_cases_on;
delete g_punit_star;
delete g_prod_mk;
delete g_pprod;
@ -1058,7 +1059,6 @@ void finalize_constants() {
delete g_unification_hint;
delete g_unification_hint_mk;
delete g_unit;
delete g_unit_cases_on;
delete g_unit_star;
delete g_monad_from_pure_bind;
delete g_user_attribute;
@ -1358,6 +1358,7 @@ name const & get_opt_param_name() { return *g_opt_param; }
name const & get_or_name() { return *g_or; }
name const & get_out_param_name() { return *g_out_param; }
name const & get_punit_name() { return *g_punit; }
name const & get_punit_cases_on_name() { return *g_punit_cases_on; }
name const & get_punit_star_name() { return *g_punit_star; }
name const & get_prod_mk_name() { return *g_prod_mk; }
name const & get_pprod_name() { return *g_pprod; }
@ -1415,7 +1416,6 @@ name const & get_true_intro_name() { return *g_true_intro; }
name const & get_unification_hint_name() { return *g_unification_hint; }
name const & get_unification_hint_mk_name() { return *g_unification_hint_mk; }
name const & get_unit_name() { return *g_unit; }
name const & get_unit_cases_on_name() { return *g_unit_cases_on; }
name const & get_unit_star_name() { return *g_unit_star; }
name const & get_monad_from_pure_bind_name() { return *g_monad_from_pure_bind; }
name const & get_user_attribute_name() { return *g_user_attribute; }

View file

@ -288,6 +288,7 @@ name const & get_opt_param_name();
name const & get_or_name();
name const & get_out_param_name();
name const & get_punit_name();
name const & get_punit_cases_on_name();
name const & get_punit_star_name();
name const & get_prod_mk_name();
name const & get_pprod_name();
@ -345,7 +346,6 @@ name const & get_true_intro_name();
name const & get_unification_hint_name();
name const & get_unification_hint_mk_name();
name const & get_unit_name();
name const & get_unit_cases_on_name();
name const & get_unit_star_name();
name const & get_monad_from_pure_bind_name();
name const & get_user_attribute_name();

View file

@ -281,6 +281,7 @@ opt_param
or
out_param
punit
punit.cases_on
punit.star
prod.mk
pprod
@ -338,7 +339,6 @@ true.intro
unification_hint
unification_hint.mk
unit
unit.cases_on
unit.star
monad_from_pure_bind
user_attribute

View file

@ -533,12 +533,13 @@ class add_mutual_inductive_decl_fn {
expr x_u = mk_local_pp("x_u", mk_app(m_basic_decl.get_c_ind_params(0), mk_app(m_putters[ind_idx], mk_sigma(rev_unpacked_sigma_args, u))));
expr unit_C = Fun(u, Pi(x_u, mk_sort(m_elim_level)));
level motive_level = get_level(m_tctx, Pi(u, Pi(x_u, mk_sort(m_elim_level))));
level unit_level = mk_level_one();
expr unit_major_premise = idx;
expr x_star = mk_local_pp("x", mk_app(m_basic_decl.get_c_ind_params(0), mk_app(m_putters[ind_idx], mk_sigma(rev_unpacked_sigma_args, mk_constant(get_unit_star_name())))));
expr unit_minor_premise = Fun(x_star, mk_app(mk_app(C, indices), x_star));
return mk_app(mk_constant(get_unit_cases_on_name(), {motive_level}), unit_C, unit_major_premise, unit_minor_premise);
return mk_app(mk_constant(get_punit_cases_on_name(), {motive_level, unit_level}), unit_C, unit_major_premise, unit_minor_premise);
}
expr A = binding_domain(ty);

View file

@ -286,6 +286,7 @@ run_cmd script_check_id `opt_param
run_cmd script_check_id `or
run_cmd script_check_id `out_param
run_cmd script_check_id `punit
run_cmd script_check_id `punit.cases_on
run_cmd script_check_id `punit.star
run_cmd script_check_id `prod.mk
run_cmd script_check_id `pprod
@ -343,7 +344,6 @@ run_cmd script_check_id `true.intro
run_cmd script_check_id `unification_hint
run_cmd script_check_id `unification_hint.mk
run_cmd script_check_id `unit
run_cmd script_check_id `unit.cases_on
run_cmd script_check_id `unit.star
run_cmd script_check_id `monad_from_pure_bind
run_cmd script_check_id `user_attribute

View file

@ -3,7 +3,7 @@ user_command.lean:14:0: error: unknown identifier 'foo'
user_command.lean:12:50: error: function expected at
()
term has type
unit
punit
foo
user_command.lean:23:8: error: command does not accept modifiers
bar