-
Notifications
You must be signed in to change notification settings - Fork 9
Allow arbitrary capability derivations #74
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
Conversation
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.
Ok. A few thoughts for clean up (can be done in a separate PR):
context
is not a very good name.handler
would be accurate. But it's also rather esoteric. We should find a good name.- I think nobody should ever have to import
Capability.Constraint
. Really, the way I see it, is that people import the modules for the capabilities they need, and it stops there. TheConstraint
module should therefore be marked as hidden for Haddock, and systematically re-exported in all the capability module. Capability.Context
is a bit different, as it gives you generic tools for capabilities (and handler) which are not in the library. There should defintitly be a module for that purpose. Though its name shouldn't be tied to the handler mechanism. There was a suggestion to hide the full definition of the classes in theCapability.Reader
and the like. Then that module could also have the full exported definition ofHasReader
(and the other).
Let me propose that such a clean up is necessary before a release.
context action = | ||
let tmDict = Dict @(inner (t m)) | ||
mDict = | ||
-- Note: this use of 'unsafeCoerce' should be safe thanks the Coercible |
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.
Cf #73
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.
This looks great!
The interface of
zoom
andmagnify
is also simplified a bit. Previously, those had a constraint of the form:forall m'. HasState outertag outer m' => HasState innertag inner (t m')
but it seems that those were not necessary. We now only request that:
HasState innertag inner (t m)
without quantifying over all
m'
s.
I think the motivation for this was to enforce that cap (t m')
was actually derived from cap m'
. It seems that this is indeed unnecessary and the new interface is certainly easier!
The interface for those three functions can be simplified by removing references to "outer" capabilities and tags.
This PR introduces a
Capability.Context.context
function that generalizes the approach taken in #73 to allow users to derive arbitrary new capabilities from the current context via a specified newtype combinator. Thezoom
andmagnify
functions are rewritten in terms of this helper.The interface of
zoom
andmagnify
is also simplified a bit. Previously, those had a constraint of the form:but it seems that those were not necessary. We now only request that:
without quantifying over all
m'
s.NOTE: Based on #73 ; change base branch before merging !