mokus0 / monad-loops

Some useful control operators for looping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iterateUntilM evauates before the loop ?

opened this issue · comments

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?

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.