[Haskell-cafe] lens and Maybe value

David Feuer david.feuer at gmail.com
Tue Dec 20 19:32:30 UTC 2022


Ah, yes, I should've thought of LensLike. I know it only works for
traversals, but why doesn't it exist in Control.Lens.Traversal?

On Tue, Dec 20, 2022, 2:30 PM Oleg Grenrus <oleg.grenrus at iki.fi> wrote:

> over can be only strict for traversals. Consider mapped [1], you cannot
> turn ordinary `fmap` into strict one.
>
> [1]:
> https://hackage.haskell.org/package/lens-5.2/docs/Control-Lens-Combinators.html#v:mapped
>
> Secondly, don't ask for ALens, if you don't need it. LensLike Solo is
> enough (and works with traversals "for free").
>
> - Oleg
> On 20.12.2022 19.43, David Feuer wrote:
>
> 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:
>
> over' :: ALens s t a b -> (a -> b) -> s -> t
> over' l f = getSolo . cloneLens l (\old -> Solo $! f old)
>   where
>     getSolo (Solo x) = x
>
> On Tue, Dec 20, 2022, 11:33 AM Tom Ellis <
> tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk> wrote:
>
>> On Tue, Dec 20, 2022 at 05:25:35PM +0100, PICCA Frederic-Emmanuel wrote:
>> > > Please clarify your question. Your code doesn't compile, and I can't
>> tell
>> > > what it's supposed to do.
>> >
>> > replace a (Maybe a) value in a data using lens only if the new (Maybe
>> a) is a Just
>>
>> How about
>>
>>     over a (mb <|>)
>>
>> ?
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20221220/a6a61b5f/attachment.html>


More information about the Haskell-Cafe mailing list