[Haskell-cafe] Using State monad with lens
mikehulluk at gmail.com
Thu Apr 2 08:01:28 UTC 2020
Thankyou everybody - this is really helpful, especially the \case technique.
@Juan I am not sure my Haskell is strong enough to use zoom yet, but I will
look into it!
On Sat, 21 Mar 2020 at 21:12, Juan Casanova <juan.casanova at ed.ac.uk> wrote:
> I'm surprised noone has mentioned 'zoom' yet. It does not make your
> original example work directly, but almost. It may be very useful to
> keep in mind as a way to do whatever you want.
> The idea of zoom is that you use it like so:
> zoom my_lens my_monadic_action
> where my_monadic_action is a monadic action that works on the
> sub-element (call it 's') of the state, and the entire thing 'zoom
> my_lens my_monadic_action' is then a monadic action that works on the
> whole element (call it 't'). my_lens is a lens that focuses on 's'
> within 't'.
> So instead of using the lens all the time in the monadic action,
> you're basically saying: "Put this everywhere that you need to", and
> then you can do things with the sub-element 's'.
> PS: I hope I did not severely misunderstand what you wanted, but it's
> still a possibility.
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe