Proposal for containers: Add 'lookup' function to Data.Set

David Feuer david.feuer at gmail.com
Mon Jul 4 16:50:03 UTC 2016


I barely care about Data.List association lists. They have no business
being in Data.List at all. If compatibility with association lists gets in
the way of a good interface, I'll take the good interface anyway.
On Jul 4, 2016 12:18 PM, "Nicolas Godbout" <nicolas.godbout at gmail.com>
wrote:

>
>
> Le 4 juil. 2016 à 11:53, David Feuer <david.feuer at gmail.com> a écrit :
>
> What we want for Map is definitely not that, but rather
>
> ??? :: Ord k => k -> Map k v -> Maybe (k, v)
>
> In each case we look up a key to retrieve an "entry" (whether we want that
> terminology or not). In the case of a Map, the entry is a key-value pair;
> in the case of a Set it is merely a key.
>
> Agreed.
>
> However, I am still scratching my head about how the functions we are
> considering would behave on Lists. The existence of 'Data.List.lookup' also
> muddles the issues since it works on association lists and not just any
> list.
>
> The challenge: find a name '???' such that all three of the following make
> sense:
>
>    ??? :: Ord a => a -> Set a -> Maybe a
>    ??? :: Eq a => a -> [a] -> Maybe a
>    ??? :: Ord k => k -> Map k v -> Maybe (k, v)
>
> A name such a 'lookupKey' looks weird on lists and sets. It is not quite a
> "containers" problem, but it would be nice to be compatible with "base"
> names.
>
> Under this spotlight, what makes sense is 'lookupElem' where elements of
> lists and sets are obvious, and the elements of a Map are defined as the
> key-value pairs. Data.Map currently has no function on elements, so this
> avenue seems open and viable.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20160704/5a767869/attachment.html>


More information about the Libraries mailing list