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

iterateUntilM evauates before the loop ? #11

Open
spinque opened this issue Mar 4, 2016 · 1 comment
Open

iterateUntilM evauates before the loop ? #11

spinque opened this issue Mar 4, 2016 · 1 comment

Comments

@spinque
Copy link

spinque commented Mar 4, 2016

untilM evaluates the condition after the loop, keeping all results.
iterateUntilM should behave the same (judging from the name), except that it returns only the final result.

However, it seems to evaluate the condition before the loop:

iterateUntilM :: (Monad m) => (a -> Bool) -> (a -> m a) -> a -> m a
iterateUntilM p f v 
    | p v       = return v
    | otherwise = f v >>= iterateUntilM p f

That confuses me. Is the naming to be unfortunate or the implementation to be incorrect?

@alexei-kopylov
Copy link

I don't think that this is a bug. The current semantics is intuitively clear: We want to iterate starting with a, until some condition. If the condition is already true we do not have to iterate.

But the fact that iterateUntilM is infix operator is indeed a bug. It should not.

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

1 participant