leanprover / leanprover/fp-lean
`Many` could be more lazy
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 192
- Forks
- 73
- PR merge metrics
- No merged PRs in 30d
Description
Thanks a lot for creating this book! It is a great learning resource.
With Many, as defined in chapter 4.3. (Example: Arithmetic in Monads), examples like
#eval (addsTo 15 (.replicate 1000 1)).take 0
quickly crash Lean (error: deep recursion). This can be remedied by changing the definition of Many.union to the one given for Many.orElse in section 5.4.2. (The Alternative Class).
The current definition of Many.bind is:
def Many.bind : Many α → (α → Many β) → Many β
| .none, _ => .none
| .more x xs, f => union (f x) (bind (xs ()) f)
The xs () in the recursive case defeats laziness. With union = orElse it becomes:
def Many.bind : Many α → (α → Many β) → Many β
| .none, _ => .none
| .more x xs, f => union (f x) (fun () => (bind (xs ()) f))
This popped up in #new members > Stuck on ManyT in "Functional Programming in Lean".
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 Many definitions and examples in chapter 4.3, then compare Many.union with Many.orElse in section 5.4.2. Reproduce the reported #eval expression with 1000 elements and verify that the lazy definition avoids the deep-recursion failure while preserving the intended Many behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100