Issue finding `Inhabited` instances in partial definition
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Checked that your issue isn't already filed.
- Reduced the issue to a self-contained, reproducible test case.
Description
The following definition fails to compile because Lean can't infer that m (Unit × β) is inhabited.
variable {α β ε : Type _} (m : Type _ → Type _) [Monad m] [MonadExcept ε m]
partial def test (q : m β) : m (Unit × β) :=
let rec loop (p : Unit) : m (Unit × β) :=
try
return (p, ← q)
catch _ => do
loop p
loop ()
The following workaround does compile.
variable {α β ε : Type _} (m : Type _ → Type _) [Monad m] [MonadExcept ε m]
partial def test' (q : m β) : m (Unit × β) :=
let inst := Inhabited.mk do return ((), (← q))
let rec loop (p : Unit) : m (Unit × β) :=
try
return (p, ← q)
catch _ => do
let _ := inst
loop p
loop ()
Both lets are necessary to compile. The second let is especially confusing, I think just fixing that would already be a significant improvement.
Versions
On MacOs with Lean (version 4.0.0-nightly-2023-04-20, commit f9da1d8b55ca, Release)
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 self-contained partial def test reproducer and compare it with the compiling test' workaround. Investigate how partial definitions infer Inhabited for m (Unit × β), especially why the inner let _ := inst changes compilation. Done means the original definition, or an equivalent minimal case, compiles without the confusing second let.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100