-
Notifications
You must be signed in to change notification settings - Fork 62
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
Consider facility to view State as Reader #179
Comments
So it turns out this was removed by @LukaJCB , see #31 What about a happy medium to allow opt-in through an optional extra import, rather than the always-on that was there previously? perhaps something like Also discovered that way back @edmundnoble wrote a law that would preclude it, but this law was later removed and now weakened to something that does permit State as Ask. For myself, I find it useful to view State as Ask, to signal in the type-signature that some code cannot update the current state. I'm not sure what the arguments against are based on, beyond the tradition that "readers read from an immutable environment". State is immutable in that sense as well, I'll remind viewers. |
I don't think I agree with this sentence (although I haven't made up my mind with respect to the entire argument). Readers reading from an immutable environment boils down to expecting: (ask, ask).tupled <-> ask.map(x => (x,x)) i.e. asking twice gives you the same result. Increasingly often though, So I feel like this issue is related to #120 Also, I think things get more interesting once you consider |
Sorry, I probably haven't been clear in what I think of the overall change: I don't mind, but we need An alternative would be to expose weaker classes as an addition to what we have: e.g. a |
I admit my previous experiences have used sequential, deterministic State and I hadn't considered the concurrent case. Seems like there are two separable dimensions here:
A question: from library user's POV, does it help or hinder them by requiring different type-classes (TCs) to read/write from concurrent vs sequential state? Different TCs imply that the choice of state representations (ie concurrent vs sequential) is baked into the code when it's written, whereas it seems (superficially) appealing to have that as a policy decision the integrator can vary later. |
Yeah, but the sort of code you can write sanely hugely depends on that. For example, having
Yeah, fwiw I don't think this request is unreasonable, it's just not what |
(at the risk of restating a pre-existing discussion) So are there four concepts here that could potentially each be a typeclass?
If the latter two are "sub-types" of, or imply, the former two, then writing a program in terms of the looser constraints (ie |
This kind of stalled with concerns around concurrent state #120, but I dont think this issue need be entangled with that. Having considered both threads, Im convinced is reasonable and safe to opt-in to viewing The thing that's not reasonable is to use Specifically, I propose |
It can be convenient to allow a MonadState[F, S] to serve as an ApplicativeAsk[F, S]. We can think of the former constraint as the ability to read and update system state, and the latter as simply the ability to read it. If all we need is to read the state, the least privilege principle suggests that a ApplicativeAsk[F, S] constraint is preferable.
Traditionally, Reader monad is associated with reading outside configuration. However, IME it also works well to read the domain model of a stateful application, or some part thereof eg by the lensing techniques available in meow-mtl.
An example of value can be found in the meow-mtl readme use case
This is a proposal to consider an opt-in extra derivation that provides an
ApplicativeAsk[F, S]
should aMonadState[F, S]
instance be available. "Opt-in" rather than automatic because the Ask- and State- may be unrelated, ifS
-type is something common likeInt
.The text was updated successfully, but these errors were encountered: