Comments (3)
Edited to add: it turns out that it works (i.e. both print 1) if we switch the order of the strategies CS.Field "r" ()
and CR.ReadStatePure
in the derivation of HasReader
for M2
. I don't really understand why this should make a difference. If this is in fact expected behavior, then at the very least I think the documentation ought to be improved/clarified; I don't remember seeing anything warning me of this pitfall.
from capability.
@byorgey Thank you for reporting! This is indeed expected behavior. I agree that this should be clarified better in the docs.
The following ordering
deriving (CR.HasReader "r" Char, CSc.HasSource "r" Char) via
(CS.Field "r" ()
(CR.ReadStatePure
(CS.MonadState
(MS.State S))))
first creates a reader in the record S
and only then focuses in on the field r
in the reader's context. I.e. the underlying implementation of local
will operate on the full record S
and will reset the whole record at the end of local
. In effect the writer and reader capability overlap on the field w
of the record S
.
On the other hand, if the order of Field
and ReadStatePure
is swapped, then the underlying implementation of local
will operate only on the field r
. I.e. the following is the correct ordering.
deriving (CR.HasReader "r" Char, CSc.HasSource "r" Char) via
(CR.ReadStatePure
(CS.Field "r" ()
(CS.MonadState
(MS.State S))))
from capability.
Ah, I get it now, thanks for the explanation! I suggest... a big fat warning attached to the Field
combinator? Or the ReadStatePure
combinator? Or both?
I wonder if there could be a way to prevent or warn about this. It is unfortunate that there are valid ways to compose the strategies that give bogus results. You need a type system for your type-level strategy combinators... =)
from capability.
Related Issues (20)
- `listen` and `pass` breaks on error or with concurrency HOT 10
- An alternative way of managing effects in `capability` HOT 4
- Capability focusing using lens? HOT 4
- HasMask capability
- Overlapping tags HOT 8
- Consider renaming library HOT 2
- Move all modules under a single namespace HOT 2
- Document Nix cache in README HOT 1
- `zoom`, `magnify`, and `wrapError` forget other capabilities
- Push haddocks to S3 from CI and link from README HOT 1
- Don't export class methods by default HOT 4
- Elimination methods in classes should be moved HOT 10
- Associate type to tags HOT 2
- `nix-shell` fails HOT 2
- GHC 8.8 compatible version
- Cannot Lift through Stream HOT 12
- Benchmark for Capability V.S. other effect handling libraries HOT 2
- Running effects locally HOT 13
- Is `derive` safe? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capability.