lean-ja / lean-by-example

コード例で学ぶ Lean 言語
https://lean-ja.github.io/lean-by-example/
MIT License
15 stars 5 forks source link

属性紹介: @[class] 属性 #309

Open Seasawher opened 2 weeks ago

Seasawher commented 2 weeks ago

see: https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/what.20is.20.60class.60.20attribute/near/445581181

MIL の7章に記述があるものの,ただの構造体との違いがわからない

Seasawher commented 2 weeks ago
variable {α : Type}

@[class] structure One (α : Type) where
  one : α

instance instOneNat : One Nat where
  one := 1

structure Two (α : Type) where
  two : α

instance instTwoNat : Two Nat where
  two := 2

example {T : Type} [One T] : True := by trivial

/--
error: invalid binder annotation, type is not a class instance
  Two T
use the command `set_option checkBinderAnnotations false` to disable the check
-/
#guard_msgs in example {T : Type} [Two T] : True := by trivial

#synth One Nat

/--
error: type class instance expected
  Two Nat
-/
#guard_msgs in #synth Two Nat