Discussion: Allow custom constraint for elem in Foldable

Henning Thielemann lemming at henning-thielemann.de
Fri Jul 28 06:42:57 UTC 2017


On Thu, 27 Jul 2017, David Feuer wrote:

> The Foldable class offers the method
>
>  elem :: Eq a => a -> t a -> Bool
>
> Unfortunately, this is really awful for sets, hash maps, etc. See
> https://stackoverflow.com/questions/45361801/implement-an-olog-n-foldable-elem-for-binary-search-trees-in-haskell#45362110
> for an example.

I'd prefer to keep Foldable Haskell-98. You may introduce methods with 
advanced types in a sub-class.

I also think that the Set type does not perfectly fit to Foldable. Most 
Set methods require Ord constraint, but Set.toList does not. Only this 
allows to have instance Foldable Set. This looks to me like an 
implementation detail. E.g. for Vector.Storable this trick does not work. 
You cannot omit the Storable constraint in Vector.toList.


More information about the Libraries mailing list