We use `MProd` instead of `Prod` to group values when expanding the `do` notation. `MProd` is a universe monomorphic product. The motivation is to generate simpler universe constraints in code that was not written by the user but generated by the `do` macro. Note that we are not really restricting the macro power since the `HasBind.bind` combinator already forces values computed by monadic actions to be in the same universe. The new test cannot be compiled without this modication.
21 lines
427 B
Text
21 lines
427 B
Text
#lang lean4
|
||
|
||
universes u
|
||
|
||
def f {α : Type u} [HasBeq α] (xs : List α) (y : α) : α := do
|
||
for x in xs do
|
||
if x == y then
|
||
return x
|
||
return y
|
||
|
||
structure S :=
|
||
(key val : Nat)
|
||
|
||
instance : HasBeq S :=
|
||
⟨fun a b => a.key == b.key⟩
|
||
|
||
theorem ex1 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨3, 0⟩ = ⟨3, 4⟩ :=
|
||
rfl
|
||
|
||
theorem ex2 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨4, 10⟩ = ⟨4, 10⟩ :=
|
||
rfl
|