Skip to content

generalize type of Data.Set.unions (from List to Foldable)? #520

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

Closed
jwaldmann opened this issue Jan 30, 2018 · 9 comments
Closed

generalize type of Data.Set.unions (from List to Foldable)? #520

jwaldmann opened this issue Jan 30, 2018 · 9 comments

Comments

@jwaldmann
Copy link
Contributor

We have unions :: Ord a => [Set a] -> Set a. Haddocks say that unions == foldl union empty
so I'd expect it to have type (Foldable t, Ord a) => t (S.Set a) -> S.Set a, the type that would be inferred when I literally use the given definition.

Yes, I know that it's S.foldl, not Data.Foldable.foldl. Why? If there is a reason, then it would be good to have it documented (visibly). But instance Foldable Set where foldl = foldl, so they are equivalent already? The actual source has unions = foldlStrict union empty, so the docs are not telling the full truth.

There is a comment at https://hackage.haskell.org/package/containers-0.5.11.0/docs/src/Utils.Containers.Internal.StrictFold.html#foldlStrict but this is hard to find? (source is there but its rendered haddock is not, since this is from other-modules)

@treeowl
Copy link
Contributor

treeowl commented Jan 30, 2018 via email

@jwaldmann
Copy link
Contributor Author

I'll see to this later this week.

@jwaldmann
Copy link
Contributor Author

Side note: the function (with the type) that I wanted is already there - it's Data.Foldable.fold, because of instance Monoid (Set a).

@jwaldmann
Copy link
Contributor Author

I made the PR since you said so, and to have a basis for discussion. Before actually adopting this -

  • should wait for benchmark results (I am running some, but it takes time, and I see no automated way to compare results)
  • what was the reason for introducing foldlStrict (was it related to IntSet.fromList slower than repeated IntSet.insert #288 perhaps - it mentions foldl)
  • contributor guidelines say "all changes in the public API must go through the libraries list"

@treeowl
Copy link
Contributor

treeowl commented Feb 2, 2018 via email

@jwaldmann
Copy link
Contributor Author

I meant the type of unions (now has Foldable)

@treeowl
Copy link
Contributor

treeowl commented Feb 2, 2018 via email

@jwaldmann
Copy link
Contributor Author

@treeowl
Copy link
Contributor

treeowl commented Mar 9, 2018

Closed by #524.

@treeowl treeowl closed this as completed Mar 9, 2018
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

No branches or pull requests

2 participants