Skip to content

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

Merged
merged 7 commits into from
Jun 15, 2019
Merged

Allow arbitrary capability derivations #74

merged 7 commits into from
Jun 15, 2019

Conversation

gdeest
Copy link
Contributor

@gdeest gdeest commented May 9, 2019

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. The zoom and magnify functions are rewritten in terms of this helper.

The interface of zoom and magnify 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.

NOTE: Based on #73 ; change base branch before merging !

@gdeest gdeest requested review from aherrmann and aspiwack as code owners May 9, 2019 09:02
Copy link
Member

@aspiwack aspiwack left a 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. The Constraint 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 the Capability.Reader and the like. Then that module could also have the full exported definition of HasReader (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
Copy link
Member

Choose a reason for hiding this comment

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

Cf #73

Copy link
Member

@aherrmann aherrmann left a 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 and magnify 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!

Gaël Deest added 5 commits June 14, 2019 16:45
The interface for those three functions can be simplified by removing references to "outer" capabilities and tags.
@gdeest gdeest changed the base branch from retain-capabilities to master June 14, 2019 15:16
@gdeest gdeest merged commit 2d7c956 into master Jun 15, 2019
@gdeest gdeest deleted the context branch June 15, 2019 11:48
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.

3 participants