lean-ja / lean-ja/lean-by-example
構造体の継承について詳細を補足する
Open
Nobody has claimed this yet.
宣言的コマンド
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
structure MythicalCreature where
large : Bool
deriving Repr
inductive Size where
| small
| medium
| large
deriving BEq, Repr
structure SizedCreature extends MythicalCreature where
size : Size
large := size == Size.large
deriving Repr
-- size を渡すだけで SizedCreature が作れる
#eval {size := .small, large := false : SizedCreature}
#eval {size := .small : SizedCreature}
-- where でも省略できる
def sample : SizedCreature where
size := .small
-- コンストラクタにおいて large にデフォルト値が与えられるわけではない
#check SizedCreature.mk (size := .small)
-- 明示的に渡すこともできる
def nonsenseCreature : SizedCreature where
large := false
size := .large
#check BEq
#print Hashable
abbrev SizesMatch (sc : SizedCreature) : Prop :=
sc.large = (sc.size == Size.large)
def huldre : SizedCreature where
size := .medium
example : SizesMatch huldre := by
simp [huldre]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No target file or test is named in the issue. Start by locating the existing documentation about Lean structure extension and read or run the provided examples. Done means the documentation explains the inheritance, default field, constructor, and proof examples shown here.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100