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

Nicolas Godbout nicolas.godbout at gmail.com
Mon Jul 4 16:18:24 UTC 2016



> 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/972c7371/attachment-0001.html>


More information about the Libraries mailing list