Skip to content
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

FoldRight fixes for Monoid/Semigroup #128

Merged
merged 1 commit into from
May 1, 2023

Conversation

7h3kk1d
Copy link
Member

@7h3kk1d 7h3kk1d commented Apr 21, 2023

Addressing #127

  • Semigroup::foldRight had parameters flipped
  • Monoid::foldRight was accumulating the accumulator from the left. This has been fixed but the identity is now used as a starting accumulator. Otherwise, the evaluation order is unchanged.
  • Changed ExplainFold parameter name since the accumulator can be in either position

Sidenote
Monoid::foldMap seems to be where short-circuiting is currently implemented. Something that was going to be addressed in the incomplete https://github.com/palatable/lambda/pull/122/files. For obvious reasons, it doesn't seem to address semigroups that should short-circuit. In addition, it has some odd behavior for Monoid::foldRight. For example the function application will now match Semigroup::foldRight, but and().foldRight(true, repeat(false)).value() does not short circuit with the current implementation of Monoid::foldRight. I'm tempted to remove foldLeft/foldRight from Monoid and add a lazilyApply to Semigroup that would allow for users to override for short-circuiting behavior.

- Semigroup::foldRight had parameters flipped
- Monoid::foldRight was accumulating the accumulator from the left. This has been fixed but the identity is now being used as a starting accumulator. Otherwise, the evaluation order is unchanged.
- Changed ExplainFold parameter name since accumulator can be in either position
@7h3kk1d 7h3kk1d requested a review from jnape April 23, 2023 14:24
@7h3kk1d 7h3kk1d merged commit d360ae8 into palatable:master May 1, 2023
3 checks passed
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.

None yet

2 participants