Skip to content

feat(PFunctor): add possible outputs and MonadAttach for free monads - #1087

Open
dtumad wants to merge 3 commits into
leanprover:mainfrom
dtumad:dtumad/freem-monad-attach
Open

dtumad wants to merge 3 commits into
leanprover:mainfrom
dtumad:dtumad/freem-monad-attach

Conversation

@dtumad

@dtumad dtumad commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds PFunctor.FreeM.possibleOutputs: x.possibleOutputs responses is the set of results x can return when each operation answers within responses op, defined as the fold of x into SetM. Allowing every response gives a lawful MonadAttach instance whose attach keeps every branch of the program, and interpreting a program by a handler can only remove possible results (canReturn_of_liftM). attachWith attaches the same proofs while interpreting into any monad, given a handler whose responses carry membership proofs. Ported from PolyFun.

AI agents were used to adapt VCVio definitions/proofs to Cslib definitions and conventions.

dtumad and others added 2 commits October 5, 2026 17:51
Add `PFunctor.FreeM.possibleOutputs responses x`, the results `x` can return
when each operation answers within `responses op`, as the fold of `x` into
`SetM`. Allowing all responses gives a lawful `MonadAttach` instance, and
interpreting a program by a handler can only remove possible results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the program first, `x.possibleOutputs responses` fixes the polynomial
before elaborating the response sets, so literals such as `fun _ => {true}`
need no annotation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `x.attachWith responses interp`, which interprets `x` in an arbitrary monad
by a handler whose responses carry membership proofs, and labels the result
with a proof that it lies in `x.possibleOutputs responses`. Erasing the proofs
recovers `x.liftM` of the underlying handler.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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