Re: Proposal for containers: Add 'lookup' function to Data.Set
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. On Jul 4, 2016 11:48 AM, "Nicolas Godbout" <nicolas.godbout@gmail.com> wrote: Correction, there are several errors in the signatures at the end of my last message. > lookup??? :: Eq a => a -> [a] -> Maybe a > lookup??? :: Ord a => a -> Set a -> Maybe a Also, copying the pattern for maps gives a slightly stranger signature > lookup??? :: (Ord k, Eq a) => (k,a) -> Map k a -> Maybe (k,a) which combines a key lookup with an equality test on the value. Nicolas. _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Le 4 juil. 2016 à 11:53, David Feuer <david.feuer@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.
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@gmail.com> wrote:
Le 4 juil. 2016 à 11:53, David Feuer <david.feuer@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.
participants (2)
-
David Feuer -
Nicolas Godbout