-
Notifications
You must be signed in to change notification settings - Fork 388
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
chore: fix the MonadStore
type classes, with semiOutParam
#4205
Conversation
Mathlib CI status (docs):
|
awaiting-review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this! ❤️ The MonadStore(1)
/MonadStore(1)Of
split looks great! However, I still have some outstanding questions on the design of the instances, along with a few minor organizational notes.
Okay, everything looks good to me! Thank you for the time you spent on this PR and explaining the situation to me! ❤️ |
The type class
MonadStore1
and friends have an outParam, which should not be an outParam, because there are multiple possible values for this parameter. At this function fetchOrCreate, there are multiple stackedStateT
monad transformers that each give a different instance toMonadStore1
. It is an implementation detail of type class synthesis which instance is found. This particular type class synthesis fails when the unused instanceLake.instMonadStore1OfMonadDStoreOfFamilyOut
is set to a lower priority, because then the synthesis order happens to go differently, so the wrong instance is found.Replacing the outParam with a semiOutParam solves this issue. Thus, we make a new type class
MonadStore1Of
, which is the same, but with a semiOutParam. This follows the design ofMonadState
andMonadStateOf
.However, then it turns out that the instance cannot anymore be synthesised.
There are two instances for
MonadStore1
:The first one is problematic during unification, especially when
β
should be instantiated as a constant function. We make the second one sufficient by adding an instance for the general type family:So then we can get rid of the first instance.