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

Support for early termination #85

Open
maoe opened this issue Feb 28, 2017 · 5 comments
Open

Support for early termination #85

maoe opened this issue Feb 28, 2017 · 5 comments

Comments

@maoe
Copy link

maoe commented Feb 28, 2017

Is there a good way to support early termination in the foldl library? Currently fold has to go though the list until the end even if head is passed.

@Gabriella439
Copy link
Owner

No, this library does not support any way for the Fold to indicate that no further input is necessary

@michaelt
Copy link
Collaborator

michaelt commented Mar 1, 2017

There is an interesting systematic attempt at this in https:/effectfully/prefolds One simple-minded point in defense of the foldl approach is that the emphasis of the library is on combining simultaneous folds e.g. liftA3 (,,) L.head (L.index 17) L.sum so though individual stock folds could exit early, their combinations tend to consume all of the input.

@maoe
Copy link
Author

maoe commented Mar 1, 2017

@michaelt Thanks for the info. That's interesting. I was thinking of something simpler like x -> a -> Maybe x or x -> a -> (Bool, x) for the step function in Fold. The argument about early termination with composition is a good point but I think it's still useful to support it.

I guess I'll see if I can support it without sacrificing the simple API and good performance.

@rizo
Copy link

rizo commented Oct 3, 2018

@Gabriel439 could you please elaborate on the decision of not including early termination in Foldl? Are you aware of any structures similar to Foldable that support termination in reducing functions?

@Gabriella439
Copy link
Owner

@rizo: I'm not aware of a similar structure that supports (A) early termination and (B) Applicative composition of Folds

The main reason why foldl does not do so is because the scope of the library is to be a replacement in spirit for Data.List.foldl. That's why the signature of the Fold type exactly matches the arguments you pass to foldl (which also does not have a termination check). There is a similar library named folds with a broader scope where this might be a better fit:

http://hackage.haskell.org/package/folds

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

4 participants