Skip to content

feat: add monad-polymorphic sorts - #861

Open
eric-wieser wants to merge 4 commits into
leanprover:mainfrom
eric-wieser:eric-wieser/mergeM
Open

feat: add monad-polymorphic sorts#861
eric-wieser wants to merge 4 commits into
leanprover:mainfrom
eric-wieser:eric-wieser/mergeM

Conversation

@eric-wieser

@eric-wieser eric-wieser commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

These can be used to:

  • replace the specialized timeM version
  • implement sorts that log as they sort
  • specialize to FreeM or PFunctor.FreeM

The old copyright dates on these files are because they were written by directly copying the corresponding non-monadic code from mathlib / lean core.

As a general pattern, writing code monad generically, then specializing it, allows Lean's compiler to compile it efficiently in Id, but also allows it to be reasoned about for richer monads m. The alternative of starting with a rich monad like FreeM and transporting back to Id has two downsides:

  • The algorithm itself must live inside CSLib, in order to have access to FreeM.
  • The compiler must be able to fully optimize out FreeM.liftM / TimeM.ret to match performance characteristics.

If you have no intent of ever executing the code then these concerns don't matter all that much. For now, the main benefit to CSLib is that we can write the algorithms just once while exploring a zoo of computation models to evaluate them in.

These can be used to:
* replace the specialized timeM version
* implement sorts that log as they sort
* specialize to FreeM or PFunctor.FreeM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant