Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Make IO universe polymorphic #3011

Open
eric-wieser opened this issue Dec 1, 2023 · 6 comments
Open

RFC: Make IO universe polymorphic #3011

eric-wieser opened this issue Dec 1, 2023 · 6 comments
Labels
RFC Request for comments

Comments

@eric-wieser
Copy link
Contributor

eric-wieser commented Dec 1, 2023

Proposal

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

This RFC does not suggest:

  • Making all monads polymorphic within a chain of binds. This requires a massive redesign, and the tradeoffs are unclear.
  • Changing any of the "real" IO api to operate in any universe other than 0.

  • User Experience: How does this feature improve the user experience?

    • Users of IO.ofExcept will not get weird universe errors if they pass in an Except from a higher universe
    • Users of types in higher universes will not have to jump between the real IO monad and a hand-rolled IOButHigherUniverse
  • Beneficiaries: Which Lean users and projects benefit most from this feature/change?

    • This would help with slim_check, which currently, in order to sample from types in higher universes, needs the monad itself to produce values in those universes
    • Mathlib's existing ULiftable infrastructure would be usable with IO; currently it cannot be because IO doesn't form a family of types over universes.
    • Users ask about this every few months
  • Maintainability: Will this change streamline code maintenance or simplify its structure?

    • The change will replace a few (a b : Type u)s with (a : Type u) (b : Type v); the consequences are negligible.

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 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.

@kim-em
Copy link
Collaborator

kim-em commented Dec 2, 2023

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

@kim-em
Copy link
Collaborator

kim-em commented Dec 2, 2023

e.g.

import Std

example : ∃ (α : Type _) (l : List α), l ≠ l ++ l := by
  refine ⟨Int, ?_⟩
  refine ⟨[37], ?_⟩
  simp

@eric-wieser eric-wieser changed the title RFC: RFC: Make IO universe polymorphic Dec 4, 2023
@eric-wieser
Copy link
Contributor Author

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

@eric-wieser
Copy link
Contributor Author

eric-wieser commented Dec 18, 2023

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
Copy link
Member

Kha commented Sep 27, 2024

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

@eric-wieser
Copy link
Contributor Author

Making EStateM.bind universe-polymorphic, as I do in #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants