<div dir="ltr">Thankyou everybody - this is really helpful, especially the \case technique.<div>@Juan I am not sure my Haskell is strong enough to use zoom yet, but I will look into it!<br></div><div>Thanks again.</div><div><br></div><div>Mike</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, 21 Mar 2020 at 21:12, Juan Casanova <<a href="mailto:juan.casanova@ed.ac.uk">juan.casanova@ed.ac.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I'm surprised noone has mentioned 'zoom' yet. It does not make your <br>
original example work directly, but almost. It may be very useful to <br>
keep in mind as a way to do whatever you want.<br>
<br>
<a href="http://hackage.haskell.org/package/lens-4.19.1/docs/Control-Lens-Zoom.html#v:zoom" rel="noreferrer" target="_blank">http://hackage.haskell.org/package/lens-4.19.1/docs/Control-Lens-Zoom.html#v:zoom</a><br>
<br>
The idea of zoom is that you use it like so:<br>
<br>
zoom my_lens my_monadic_action<br>
<br>
where my_monadic_action is a monadic action that works on the <br>
sub-element (call it 's') of the state, and the entire thing 'zoom <br>
my_lens my_monadic_action' is then a monadic action that works on the <br>
whole element (call it 't'). my_lens is a lens that focuses on 's' <br>
within 't'.<br>
<br>
So instead of using the lens all the time in the monadic action, <br>
you're basically saying: "Put this everywhere that you need to", and <br>
then you can do things with the sub-element 's'.<br>
<br>
Juan.<br>
<br>
PS: I hope I did not severely misunderstand what you wanted, but it's <br>
still a possibility.<br>
<br>
-- <br>
The University of Edinburgh is a charitable body, registered in<br>
Scotland, with registration number SC005336.<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>