
5 Jan
2009
5 Jan
'09
8:16 a.m.
Hi, is there a reason why there is no monadic version of "until" in the Haskell libraries? It would be defined as follows: untilM :: (Monad m) => (a -> Bool) -> (a -> m a) -> a -> m a untilM p f x | p x = return x | otherwise = f x >>= untilM p f The same applies to scanM, also not part of the libraries: scanM :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m [a] scanM f q [] = return [q] scanM f q (x:xs) = do q2 <- f q x qs <- scanM f q2 xs return (q:qs) I often find myself in need for these. To me these seem idiomatic enough to be included in the library. But since they is not, I guess there must be another, more idiomatic way to do this. Thank you, Jan