lean4-htt/tests/lean/run/forInColErr.lean
Eric Wieser 9338aabed9
fix: move the monad argument for ForIn, ForIn', and ForM (#10204)
This PR changes the interface of the `ForIn`, `ForIn'`, and `ForM`
typeclasses to not take a `Monad m` parameter. This is a breaking change
for most downstream `instance`s, which will will now need to assume
`[Monad m]`.

The rationale is that if the provider of an instance requires `m` to be
a Monad, they should assume this up front. This makes it possible for
the instanve to assume `LawfulMonad m` or some other stronger
requirement, and also to provided a concrete instance for a particular
`m` without assuming a non-canonical `Monad` structure on it.

Zulip: [#lean4 > Monad assumptions in fields of other typeclasses @
💬](https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/Monad.20assumptions.20in.20fields.20of.20other.20typeclasses/near/537102158)
2025-11-25 12:20:37 +00:00

79 lines
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

set_option pp.mvars.anonymous false
/--
error: failed to construct 'ForIn' instance for collection
?_
and monad
Id
-/
#guard_msgs in
example {c} := Id.run do
for x in c do
pure ()
pure ()
/--
error: don't know how to synthesize implicit argument `ρ`
@forIn Id (List ?_) ?_ instForInOfForIn' PUnit [] PUnit.unit fun x r => do
pure ()
pure (ForInStep.yield PUnit.unit)
context:
⊢ Type _
---
error: Failed to infer type of binder `x`
---
error: don't know how to synthesize implicit argument `α`
@List.nil ?_
context:
⊢ Type _
-/
#guard_msgs in
example : Unit := Id.run do
for x in [] do
pure ()
pure ()
/--
error: failed to construct `ForIn'` instance for collection
?_
and monad
Id
-/
#guard_msgs in
example {c} := Id.run do
for h : x in c do
pure ()
pure ()
/--
error: don't know how to synthesize implicit argument `d`
@forIn' Id (List ?_) ?_ inferInstance List.instForIn'InferInstanceMembershipOfMonad PUnit [] PUnit.unit fun x h r =>
do
pure ()
pure (ForInStep.yield PUnit.unit)
context:
⊢ outParam (Membership ?_ (List ?_))
---
error: don't know how to synthesize implicit argument `ρ`
@forIn' Id (List ?_) ?_ inferInstance List.instForIn'InferInstanceMembershipOfMonad PUnit [] PUnit.unit fun x h r =>
do
pure ()
pure (ForInStep.yield PUnit.unit)
context:
⊢ Type _
---
error: Failed to infer type of binder `h`
---
error: Failed to infer type of binder `x`
---
error: don't know how to synthesize implicit argument `α`
@List.nil ?_
context:
⊢ Type _
-/
#guard_msgs in
example : Unit := Id.run do
for h : x in [] do
pure ()
pure ()