f177082c3b
@avigad and @fpvandoorn, I changed the metaclasses names. They were not uniform: - The plural was used in some cases (e.g., [coercions]). - In other cases a cryptic name was used (e.g., [brs]). Now, I tried to use the attribute name as the metaclass name whenever possible. For example, we write definition foo [coercion] ... definition bla [forward] ... and open [coercion] nat open [forward] nat It is easier to remember and is uniform.
60 lines
1.3 KiB
Text
60 lines
1.3 KiB
Text
import logic
|
|
namespace experiment
|
|
namespace algebra
|
|
inductive mul_struct [class] (A : Type) : Type :=
|
|
mk : (A → A → A) → mul_struct A
|
|
|
|
definition mul {A : Type} [s : mul_struct A] (a b : A)
|
|
:= mul_struct.rec (λ f, f) s a b
|
|
|
|
infixl `*` := mul
|
|
end algebra
|
|
|
|
open algebra
|
|
namespace nat
|
|
inductive nat : Type :=
|
|
| zero : nat
|
|
| succ : nat → nat
|
|
|
|
constant mul : nat → nat → nat
|
|
constant add : nat → nat → nat
|
|
|
|
definition mul_struct [instance] : algebra.mul_struct nat
|
|
:= algebra.mul_struct.mk mul
|
|
end nat
|
|
|
|
section
|
|
open algebra nat
|
|
variables a b c : nat
|
|
check a * b * c
|
|
definition tst1 : nat := a * b * c
|
|
end
|
|
|
|
section
|
|
open [notation] algebra
|
|
open nat
|
|
-- check mul_struct nat << This is an error, we opened only the notation from algebra
|
|
variables a b c : nat
|
|
check a * b * c
|
|
definition tst2 : nat := a * b * c
|
|
end
|
|
|
|
section
|
|
open nat
|
|
-- check mul_struct nat << This is an error, we opened only the notation from algebra
|
|
variables a b c : nat
|
|
check a*b*c
|
|
definition tst3 : nat := a*b*c
|
|
end
|
|
|
|
section
|
|
open nat
|
|
set_option pp.implicit true
|
|
definition add_struct [instance] : algebra.mul_struct nat
|
|
:= algebra.mul_struct.mk add
|
|
|
|
variables a b c : nat
|
|
check #experiment.algebra a*b*c -- << is open add instead of mul
|
|
definition tst4 : nat := #experiment.algebra a*b*c
|
|
end
|
|
end experiment
|