lean-ja / lean-ja/lean-by-example
List.foldl の使用例:二項演算の双方の型が同じではないケース(累積)
Open
Nobody has claimed this yet.
コード例
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
Lean 99 の Problem 57 より
def BinTree.searchTreeFromList [Ord α] (xs : List α) : BinTree α :=
-- sorry
xs.foldl insert BinTree.empty
where
insert : BinTree α → α → BinTree α
| .empty, x => leaf x
| .node v l r, x =>
match compare x v with
| .lt => BinTree.node v (insert l x) r
| _ => BinTree.node v l (insert r x)
-- sorry
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
Start with the Problem 57 reference and the List.foldl/BinTree.searchTreeFromList snippet in the issue. Locate the appropriate example in the repository, and consider the work complete when it clearly demonstrates a fold whose accumulator and element types differ.
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
- 45/100