[Haskell-cafe] Pesky monads...

Andrew Coppin andrewcoppin at btinternet.com
Sat May 19 15:12:41 EDT 2007


Matthew Cox wrote:
> You can define one:
>
> untilM :: Monad m => (a -> Bool) -> (a -> m a) -> a -> m a
> untilM pred f x | pred x = return x
>                 | otherwise = f x >>= untilM pred f
>
> Matthew Cox
>   
Hey, neat! :-D

Mmm, I wonder if one could use "fail" to exit the loop instead... Oh, 
wait, for some monads that fires an error. Hmm. Nice try.



More information about the Haskell-Cafe mailing list