[Haskell-beginners] untilM and scanM

Jan Snajder jan.snajder at fer.hr
Mon Jan 5 08:16:11 EST 2009


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



More information about the Beginners mailing list