lean4-htt/tests/lean/IRbug.lean
2020-10-27 18:29:19 -07:00

24 lines
688 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