Lookup variant for IntMap

Andrew Martin andrew.thaddeus at gmail.com
Mon Aug 16 14:49:09 UTC 2021


This is an interesting question. As a general rule, I tend to write code
that is optimized for the success case, but usually, I'm thinking about
things like parsing, where failure is extremely uncommon. With an ordered
map, there are certainly situations where failure is the more common case.
However, one important question is: What are you going to do if the element
is not present? One possibility is to add the missing value. But if you're
doing that, then you chose the wrong operation to begin with. Alter (known
as upsert in other ecosystems) outperforms the combination of lookup and
insert, or at least it should. That's all I can think of at the moment on
this topic. It would interesting to see if someone is aware of a situation
where the current behavior is advantageous.

On Mon, Aug 16, 2021 at 8:13 AM Callan McGill <callan.mcgill at gmail.com>
wrote:

> Hi all,
>
> I recently noticed that lookup for IntMap favours searches that can
> fast-fail - if instead we are in a situation where lookups are mostly
> successful, then this can be wasteful (see this issue for details:
> https://github.com/haskell/containers/issues/794). Since both versions
> are useful, it would be best to offer users both variants.
>
> I wondered if people on this list had any suggestions for a name for the
> new function?  David Feuer also wondered which of these two behaviours
> should be the default. My inclination is for it to be the current version
> which fails faster (this also guarantees no unfortunate regressions) but it
> would be useful to run more substantial real-world benchmarks to figure
> that out (if anyone has any suggestions then do let me know).
>
> Best wishes,
> Callan
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>


-- 
-Andrew Thaddeus Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20210816/711a7995/attachment.html>


More information about the Libraries mailing list