Faster `elem` "Hack" for Data.Set?

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Sun Jan 30 08:54:35 UTC 2022


On Sat, Jan 29, 2022 at 07:25:16PM -0500, Viktor Dukhovni wrote:
> it was observed that a similar approach can be used to give Data.Set a
> performant `elem` method

But why?  It is impossible to program polymorphically in a meaningful
way with Foldable, because Foldable has no coherent operational
semantics.  We discussed this at:

https://github.com/haskell/core-libraries-committee/issues/20

If we could "improve" Set's `elem` instance what would that gain us?
That we could write a Foldable-polymorphic function that works well on
Set and badly on []?  Then wy not just specialise to Set in the first
place?  Trying to "improve" Foldable instances seems like a fool's
errand to me, especially if it trades off simplicity somewhere else.

Tom




More information about the Libraries mailing list