containers icon indicating copy to clipboard operation
containers copied to clipboard

Add 'lookup' function to Data.Set

Open DrNico opened this issue 8 years ago • 11 comments

This is an implementation of the proposal submitted as Issue #290, but not yet discussed on the Haskell libraries list.

DrNico avatar Jun 27 '16 21:06 DrNico

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).

treeowl avatar Jun 29 '16 19:06 treeowl

Could you also add a similar function to Data.IntSet and Data.IntMap?

m-renaud avatar Dec 26 '17 02:12 m-renaud

@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.

treeowl avatar Dec 26 '17 02:12 treeowl

@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.

treeowl avatar Dec 26 '17 02:12 treeowl

The mailing list discussion thread begins with https://mail.haskell.org/pipermail/libraries/2016-June/027116.html

treeowl avatar Dec 26 '17 02:12 treeowl

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)

m-renaud avatar Dec 26 '17 18:12 m-renaud

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 .

treeowl avatar Dec 26 '17 18:12 treeowl

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?

m-renaud avatar Dec 26 '17 19:12 m-renaud

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 .

treeowl avatar Dec 26 '17 19:12 treeowl

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.

m-renaud avatar Dec 26 '17 19:12 m-renaud

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?

sjakobi avatar Jul 15 '20 02:07 sjakobi