Skip to content

Refactor lattice flipping for modes #3949

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

riaqn
Copy link
Contributor

@riaqn riaqn commented Apr 30, 2025

Currently in solver.ml there is Solver_mono which can handle monotone morphisms. Based on that, there are two polarized solvers Positive and Negative, used for comonadic and monadic axes respectively. The intention is such that user code (mode.ml) doesn't need to think about the flipping. This has two issues:

  • It turns out that mode.ml still needs to think about the flipping in some definitions but not all of them. This mixture, and the fact that both mode.ml and solver.ml handles flipping, makes the code more confusing.
  • Positive.t and Negative.t are different types and complicates type polymorphism. In particular, Value.Axis.t is a complicated GADT.

So we remove both Positive and Negative, and let mode.ml to be the only file that cares about flipping. We move some code such that the flipping are concentrated to fewer places.

The downside is that code that uses mode might see (Uniqueness.Const.t, allowed * disallowed) mode instead of (disallowed * allowed) Uniqueness.t. The two types are the same, but ideally we want to show the latter.

Review

Please review by commit.

@riaqn riaqn requested a review from goldfirere April 30, 2025 11:04
Comment on lines -2932 to -2933
| Meet_with : 'a -> (('a, 'l * 'r) mode_comonadic, 'a) raw
| Join_with : 'a -> (('a, 'l * 'r) mode_monadic, 'a) raw
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This GADT was intended to encode the fact that Meet_with can be only applied on comonadic axes, to remove the assertion at L2988. But it doesn't seem to be work, so I'm simplify it.

Comment on lines +2339 to +2341
type ('a, 'd0, 'd1) t =
| Monadic : (Monadic.Const.t, 'a) Axis.t -> ('a, 'd, 'd neg) t
| Comonadic : (Comonadic.Const.t, 'a) Axis.t -> ('a, 'd, 'd pos) t
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH the new GADT doesn't seem much simpler than before, but at least it no longer mentions mode_monadic and mode_comonadic, and instead uses allowance to encode flipping.

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