containers
containers copied to clipboard
Add 'lookup' function to Data.Set
This is an implementation of the proposal submitted as Issue #290, but not yet discussed on the Haskell libraries list.
Unless someone comes up with a better name, or a good reason to dislike this one, I'd like to go with @andreasabel's suggestion of lookupEntry
, and to add to Data.Map
lookupEntry :: Ord k => k -> Map k v -> Maybe (k, v)
.
Could you also add a similar function to Data.IntSet
and Data.IntMap
?
@m-renaud In the library list discussion, several people thought this was a bad idea. I believe that included @wrengr. They thought this sort of interning operation would be best handled by another data structure. Nothing about this is at all relevant to Data.IntMap
or Data.IntSet
; they (operationally) store Int#
values, not Int
values, so there can be no duplication.
@m-renaud, sorry, I ascribed the wrong objection to @wrengr. She opposed calling this a name relating to interning. The main dispute on the libraries list had to do with the name. The name lookup
seems very strange to me here.
The mailing list discussion thread begins with https://mail.haskell.org/pipermail/libraries/2016-June/027116.html
Nothing about this is at all relevant to Data.IntMap or Data.IntSet
Ahh, that makes sense.
The main dispute on the libraries list had to do with the name
Gotcha. Reading through the discussion it seems like everyone was okay with lookupEntry
as you mention in your comment above. The only hesitation was that for sets the term "entry" doesn't existing in the vocabulary. Should we start a new thread with a proposal with the functions to make sure everyone is on board still?
lookupEntry :: Ord a => a -> Set a -> Maybe a
lookupEntry :: Ord k => k -> Map k v -> Maybe (k, v)
Go ahead.
On Dec 26, 2017 1:01 PM, "Matt Renaud" [email protected] wrote:
Nothing about this is at all relevant to Data.IntMap or Data.IntSet
Ahh, that makes sense.
The main dispute on the libraries list had to do with the name
Gotcha. Reading through the discussion it seems like everyone was okay with lookupEntry as you mention in your comment above. The only hesitation was that for sets the term "entry" doesn't existing in the vocabulary. Should we start a new thread with a proposal with the functions to make sure everyone is on board still?
lookupEntry :: Ord a => a -> Set a -> Maybe a lookupEntry :: Ord k => k -> Map k v -> Maybe (k, v)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/haskell/containers/pull/291#issuecomment-353995588, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_YV4bsgzz2LU3skO4iqZdhmTVaUgks5tETRfgaJpZM4I_hrB .
Giving this some more thought, why add lookupEntry
for Data.Map? Map already has lookup :: k -> Map k v -> Maybe v
, so if you really wanted you could implement Map.lookupEntry k m = (\v -> (k,v)) <$> lookup k m
without loss of performance.
Also, since "entry" is really parlance related to maps, removing this from Map means we could use the more appropriate term "elem(ent)": lookupElement :: (Ord a) => a -> Set a -> Maybe a
.
WDYT?
The purpose for maps would be to extract the exact stored key. The keys in the map correspond to the ones in a set; values are extra.
On Dec 26, 2017 2:04 PM, "Matt Renaud" [email protected] wrote:
Giving this some more thought, why add lookupEntry for Data.Map? Map already has lookup :: k -> Map k v -> Maybe v, so if you really wanted you could implement Map.lookupEntry k m = (\v -> (k,v)) <$> lookup k m without loss of performance.
Also, since "entry" is really parlance related to maps, removing this from Map means we could use the more appropriate term "elem(ent)": lookupElement :: (Ord a) => Set a -> Maybe a.
WDYT?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/haskell/containers/pull/291#issuecomment-354001799, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzi_dr9VSErn8BIqMP-C0E3dd8K-DjZks5tEUMxgaJpZM4I_hrB .
The purpose for maps would be to extract the exact stored key.
Thanks for the clarification; I retract my previous comment. I'll go ahead and send a proposal to libraries for the two lookupEntry
methods in https://github.com/haskell/containers/pull/291#issuecomment-353995588.
Thanks for the clarification; I retract my previous comment. I'll go ahead and send a proposal to libraries for the two
lookupEntry
methods in #291 (comment).
Did that libraries proposal ever happen?