lean-ja / lean-ja/lean-by-example
Applicative 使用例: Tree の traverse
Open
Nobody has claimed this yet.
コード例
- Dominant language
- Lean
- Stars
- 188
- Forks
- 15
- Avg merge
- 9h 8m
- Merged PRs (30d)
- 6
Description
/-- A binary tree with values stored in non-leaf nodes. -/
inductive Tree.{u} (α : Type u) : Type u
| nil : Tree α
| node : α → Tree α → Tree α → Tree α
deriving DecidableEq, Repr
compile_inductive% Tree
namespace Tree
universe u
variable {α : Type u}
instance : Inhabited (Tree α) :=
⟨nil⟩
/--
Do an action for every node of the tree.
Actions are taken in node -> left subtree -> right subtree recursive order.
This function is the `traverse` function for the `Traversable Tree` instance.
-/
def traverse {m : Type* → Type*} [Applicative m] {α β} (f : α → m β) : Tree α → m (Tree β)
| .nil => pure nil
| .node a l r => .node <$> f a <*> traverse f l <*> traverse f r
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
The issue provides a Lean definition of Tree and its traverse function, but names no target file or test. First locate the repository entry point for code examples or the mdBook documentation, then determine where this Applicative example belongs; done means the Tree traverse example is included in the appropriate documentation and renders or builds successfully.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100