Skip to content

Conversation

@treeowl
Copy link
Collaborator

@treeowl treeowl commented Mar 18, 2018

  • Index Arrays and SmallArrays eagerly.
  • Fix foldl1 for Array, which was completely wrong.
  • Make the structure of the Foldable instances for Array
    and SmallArray the same, taking what I thought was the best
    from each.

Fixes #86

@cartazio
Copy link
Contributor

cartazio commented Mar 18, 2018 via email

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 18, 2018

Oh, I just meant the way the code is written. fix vs explicit recursion, the way the first/last element is handled in foldr1/foldl. I also removed the explicit toList implementations because they really just did the same as the default ones in the same way, which seemed a bit silly.

* Index `Array`s and `SmallArray`s eagerly.
* Fix `foldl1` for `Array`, which was completely wrong.
* Make the structure of the `Foldable` instances for `Array`
  and `SmallArray` the same, taking what I thought was the best
  from each.

Fixes haskell#86
Copy link
Member

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

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

I haven't looked over everything in detail, but this looks good overall. As you note in #89, it would be nice to have a regression test for foldl'. We could:

  1. Wait until the test suite is overhauled, and then rebase this PR on top of that
  2. Merge this now, and ask that you write a regression test later :)

Which option would you prefer?

| (# x #) <- indexSmallArray## ary i
= go (i+1) (min e x)
{-# INLINE minimum #-}
sum = foldl' (+) 0
Copy link
Member

Choose a reason for hiding this comment

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

Out of curiosity, does this generate better code than the default implementation for sum (which is something like getSum . foldMap Sum)?

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 19, 2018 via email

@RyanGlScott RyanGlScott merged commit a263cc2 into haskell:master Mar 19, 2018
@treeowl
Copy link
Collaborator Author

treeowl commented Mar 19, 2018 via email

@andrewthad
Copy link
Collaborator

For posterity's sake, I'll point out that foldl1 is incorrect in this PR but has been fixed in #99.

@treeowl
Copy link
Collaborator Author

treeowl commented Mar 23, 2018 via email

@andrewthad
Copy link
Collaborator

Maybe you accidentally picked a list that was the reversal of itself. Or maybe you accidentally revert part of your changes before committing. Either way, not a big deal now that we have decent tests.

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.

4 participants