<div dir="auto">What's the principle for choosing between LensLike Solo and ATraversal?</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Dec 20, 2022, 2:30 PM Oleg Grenrus <<a href="mailto:oleg.grenrus@iki.fi">oleg.grenrus@iki.fi</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<p>over can be only strict for traversals. Consider mapped [1], you
cannot turn ordinary `fmap` into strict one.<br>
<br>
[1]:
<a href="https://hackage.haskell.org/package/lens-5.2/docs/Control-Lens-Combinators.html#v:mapped" target="_blank" rel="noreferrer">https://hackage.haskell.org/package/lens-5.2/docs/Control-Lens-Combinators.html#v:mapped</a><br>
<br>
Secondly, don't ask for ALens, if you don't need it. LensLike Solo
is enough (and works with traversals "for free").<br>
<br>
- Oleg<br>
</p>
<div>On 20.12.2022 19.43, David Feuer wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">
<div>That's nice and clean, but it leaves a thunk inside (since
the field is lazy). Is there a strict version of `over` that
avoids this? We could write one thus:</div>
<div dir="auto"><br>
</div>
<div dir="auto">over' :: ALens s t a b -> (a -> b) -> s
-> t</div>
<div dir="auto">over' l f = getSolo . cloneLens l (\old ->
Solo $! f old)</div>
<div dir="auto"> where</div>
<div dir="auto"> getSolo (Solo x) = x</div>
<div dir="auto"><br>
<div class="gmail_quote" dir="auto">
<div dir="ltr" class="gmail_attr">On Tue, Dec 20, 2022,
11:33 AM Tom Ellis <<a href="mailto:tom-lists-haskell-cafe-2017@jaguarpaw.co.uk" rel="noreferrer noreferrer" target="_blank">tom-lists-haskell-cafe-2017@jaguarpaw.co.uk</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue,
Dec 20, 2022 at 05:25:35PM +0100, PICCA Frederic-Emmanuel
wrote:<br>
> > Please clarify your question. Your code doesn't
compile, and I can't tell<br>
> > what it's supposed to do.<br>
> <br>
> replace a (Maybe a) value in a data using lens only
if the new (Maybe a) is a Just<br>
<br>
How about<br>
<br>
over a (mb <|>)<br>
<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 noreferrer noreferrer 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>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank" rel="noreferrer">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
Only members subscribed via the mailman list are allowed to post.</pre>
</blockquote>
</div>
_______________________________________________<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 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>