leanprover / lean4

Lean 4 programming language and theorem prover
https://lean-lang.org
Apache License 2.0
4.61k stars 410 forks source link

RFC: Make `IO` universe polymorphic #3011

Open eric-wieser opened 10 months ago

eric-wieser commented 10 months ago

Proposal

Right now, we have IO : Type → Type. This RFC suggests we change to IO : Type u → Type u.

This RFC does not suggest:


Community Feedback

Some initial discussion, which suggests some benefit would arise even from just changing IO to allow higher universes: https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/universe.20polymorphic.20IO/near/282494539

Impact

Add :+1: to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add :+1: to it.

kim-em commented 10 months ago

I don't understand the motivation here. slim_check should not be sampling from higher universes in the first place.

kim-em commented 10 months ago

e.g.

import Std

example : ∃ (α : Type _) (l : List α), l ≠ l ++ l := by
  refine ⟨Int, ?_⟩
  refine ⟨[37], ?_⟩
  simp
eric-wieser commented 10 months ago

That example is a bit misleading, because Lean unifies the _ to 0. It fails if you use Type u.

eric-wieser commented 10 months ago

leanprover-community/mathlib4#9135 makes slim_check work on that statement, but it can't easily be generalized to do work in the IO monad unless we make the change suggested in this RFC.

Kha commented 3 weeks ago

How would you ever make use of a higher-universe IO if main etc. remain in IO.{0}?

eric-wieser commented 3 weeks ago

Making EStateM.bind universe-polymorphic, as I do in https://github.com/leanprover/lean4/pull/3010, is sufficient I think. You wouldn't be able to use do notation to jump between universes, but you could call EStateM.bind directly, or an IO.bind wrapper for it.