Skip to content

add nubOrd and friends #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 26, 2018
Merged

add nubOrd and friends #515

merged 2 commits into from
Jan 26, 2018

Conversation

gbaz
Copy link
Contributor

@gbaz gbaz commented Jan 25, 2018

resolves #439

I think I have the asymptotics for nubInt right, but a sanity check wouldn't hurt...

@treeowl
Copy link
Contributor

treeowl commented Jan 25, 2018 via email

go s (x:xs) = if x `Set.member` s then go s xs
else x : go (Set.insert x s) xs

-- | The `nubOrdOn` function behaves just like `nubOrd` except it preforms comparisons not on the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performs, not preforms.

else x : go (IntSet.insert x s) xs

-- | The `nubIntOn` function behaves just like 'nubInt' except it preforms comparisons not on the
-- original datatype, but a user-specified projection from that datatype to 'Int'.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performs, not preforms.

-- | The `nubIntOn` function behaves just like 'nubInt' except it preforms comparisons not on the
-- original datatype, but a user-specified projection from that datatype to 'Int'.
nubIntOn :: (a -> Int) -> [a] -> [a]
nubIntOn f l = go IntSet.empty l
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eta reduce. And it's probably slightly faster to make f an argument to go, here and above.

@treeowl
Copy link
Contributor

treeowl commented Jan 25, 2018

Actually, I changed my mind. We want to let f have the chance to inline, so keep it pulled out.

@treeowl
Copy link
Contributor

treeowl commented Jan 25, 2018

However however, inlining f is only useful if we make this participate in list fusion. So let's do that too.

@gbaz
Copy link
Contributor Author

gbaz commented Jan 26, 2018

Added tests, fixed typo, eta reduced.

I did not add fusion. I took a run at it and it wasn't straightforward. Doing a foldr doesn't really work because it reverses the direction in which things are dropped. So that means making it a good consumer is hard. Further, the way in which we end up building out of the fold (which involves taking a snd of the result, since we need to pass around a pair) is rather ugly and I think gets in the way of making it a good producer.

@treeowl
Copy link
Contributor

treeowl commented Jan 26, 2018 via email

@gbaz
Copy link
Contributor Author

gbaz commented Jan 26, 2018

I don't know what that means. In any case, I tried, and didn't get it working. If you know how to get it working, I suggest we merge first, and then you make a further patch.

@treeowl
Copy link
Contributor

treeowl commented Jan 26, 2018 via email

@gbaz
Copy link
Contributor Author

gbaz commented Jan 26, 2018

Ok, is this good to merge then?

@treeowl treeowl merged commit 0e4a010 into haskell:master Jan 26, 2018
@treeowl
Copy link
Contributor

treeowl commented Jan 26, 2018

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add ordNub somewhere in containers
2 participants