Skip to content

Conversation

@treeowl
Copy link
Contributor

@treeowl treeowl commented Dec 24, 2014

Additionally, use coercions to speed up folds.

@treeowl treeowl force-pushed the foldlp branch 3 times, most recently from 2c4ed33 to 3e85228 Compare December 30, 2014 17:37
@treeowl
Copy link
Contributor Author

treeowl commented Dec 30, 2014

One possible way to reduce confusion would be to stop making Elem a Foldable instance at all, and just do what needs to be done in each version of f' for each fold. The Foldable instance for Elem is (I believe) used only to make functions for the Seq folds to toss down to FingerTree.

@treeowl
Copy link
Contributor Author

treeowl commented Dec 30, 2014

Hang on with this for a bit. I just realized some things can safely be made stricter, which could help GHC make better code. For example, we can safely make foldr' and foldl' for Node strict in the initial value of the accumulator, and we may be able to play some similar tricks with FingerTree. I'm going to need to run some benchmarks and pore over some Core to figure out just how to do this right. Separating the first layer of the FingerTree from the rest (which will likely help with this) may also avoid the need for at least some of the coercions.

Additionally, use coercions to speed up folds.
@sjakobi
Copy link
Member

sjakobi commented Jul 15, 2020

@treeowl

Hang on with this for a bit. I just realized some things can safely be made stricter, which could help GHC make better code. For example, we can safely make foldr' and foldl' for Node strict in the initial value of the accumulator, and we may be able to play some similar tricks with FingerTree. I'm going to need to run some benchmarks and pore over some Core to figure out just how to do this right. Separating the first layer of the FingerTree from the rest (which will likely help with this) may also avoid the need for at least some of the coercions.

If this PR already is an improvement on the status quo, I'd advocate merging it and leaving the other ideas for future work.

In general, I think we should try not letting the perfect stand in the way of good.

@treeowl
Copy link
Contributor Author

treeowl commented Jul 15, 2020 via email

@sjakobi
Copy link
Member

sjakobi commented Jul 15, 2020

Good! :)

@treeowl I'd suggest that you fix the merge conflicts then and bring this to a state where you're happy [EDIT: enough] with it, and then say when you want a review.

Maybe @Lysxia could help with the review then?! I think he knows Data.Sequence much better than I do!

@Lysxia
Copy link
Contributor

Lysxia commented Jul 15, 2020

Sure, you can ping me to have a look at this.

@meooow25
Copy link
Contributor

Custom foldl' and foldr' were added in #281.

@meooow25 meooow25 closed this Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants