lean4-htt/tests/lean/IRbug.lean
Kim Morrison ea221f3283
feat: Nat.(fold|foldRev|any|all)M? take a function which sees the upper bound (#6139)
This PR modifies the signature of the functions `Nat.fold`,
`Nat.foldRev`, `Nat.any`, `Nat.all`, so that the function is passed the
upper bound. This allows us to change runtime array bounds checks to
compile time checks in many places.
2024-11-22 03:05:51 +00:00

24 lines
690 B
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.

namespace Repro
def FooM (α : Type) : Type := Unit → α
def FooM.run {α : Type} (ψ : FooM α) (x : Unit) : α := ψ x
def bind {α β : Type} : ∀ (ψ₁ : FooM α) (ψ₂ : α → FooM β), FooM β
| ψ₁, ψ₂ => λ _ => ψ₂ (ψ₁.run ()) ()
instance : Pure FooM := ⟨λ x => λ _ => x⟩
instance : Bind FooM := ⟨@bind⟩
instance : Monad FooM := {}
def unexpectedBehavior : FooM String := do
let b : Bool := (#[] : Array Nat).isEmpty;
let trueBranch ← pure "trueBranch";
let falseBranch ← pure "falseBranch";
(1 : Nat).foldM (λ _ _ (s : String) => do
let s ← pure $ if b then trueBranch else falseBranch; pure s) ""
#eval unexpectedBehavior ()
end Repro