Skip to content

Conversation

@gdeest
Copy link
Contributor

@gdeest gdeest commented May 7, 2019

This change allows callers of the Capability.State.zoom and Capability.Reader.magnify functions to pass along a set of capabilities from the current monadic context to the focusing action. Retained capabilities are specified via a typelevel parameter of kind [(* -> *) -> Constraint].

Implementation relies on unsafeCoerce to convert a dictionary for a wrapped monad instance to the original monad.

Fixes #46.

@gdeest gdeest requested review from aherrmann and aspiwack as code owners May 7, 2019 09:48
This change allows callers of the `Capability.State.zoom` and `Capability.Reader.magnify` functions to pass along a set of capabilities from the current monadic context
to the focusing action. Retained capabilities are specified via a typelevel parameter of kind `[(* -> *) -> Constraint]`.

Implementation relies on `unsafeCoerce` to convert a dictionary for a wrapped monad instance to the original monad.

Fixes #46.
@"foobar" @"foo" @(Rename 1 :.: Pos 1 "foobar")
@('[HasState "foobar" (Int,Int)]) $ do
incFoo
incFoobar
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that we should encourage people to have to concurrent HasState instances. It's technically legal, but it may be surprising. I shouldn't prevent us from merging this, but maybe we will want to split this into a two-state example and a zoom-while-preserving-stuff example (with, for instance, a magnifyError while preservinig a state).

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.

Looks good, thank you! #46 also lists wrapError, which is not addressed by this PR. What's the reasoning for that? Should we keep #46 open until wrapError is also addressed?

-- See <https://github.com/tweag/capability/issues/46>.
zoom :: forall outertag innertag t outer inner m a.
( forall x. Coercible (t m x) (m x)
zoom :: forall outertag innertag t (cs :: [(* -> *) -> Constraint]) outer inner m a.
Copy link
Member

Choose a reason for hiding this comment

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

Same question about aliasing. Maybe it's worth a sentence in the docs.

@gdeest
Copy link
Contributor Author

gdeest commented May 9, 2019

@aherrmann Right, I skipped wrapError. I'll handle it in #74 ; we can keep #46 open in the mean time.

@gdeest gdeest force-pushed the retain-capabilities branch from ed634df to 3450330 Compare May 9, 2019 15:46
@gdeest gdeest merged commit 5ba7682 into master Jun 14, 2019
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.

zoom, magnify, and wrapError forget other capabilities

4 participants