So, the next question is: Why isn't this already in Control.Monad?

On Mar 21, 2007, at 8:27 AM, Jules Bean wrote:

David F. Place wrote:
Interesting, but what if 'p' is also a monadic action? For instance, it might access the state of the State monad which 'f' is updating.

Then I'd stop trying to do it as a one-liner, I suspect:

let untilM p f x = do
 cond <- p x
 if cond then return x
  else do y <- f x
          untilM p f y




On Mar 21, 2007, at 5:31 AM, Jules Bean wrote:

..but here 'f' is a pure function, not a monadic action. If you want f to be a monadic action then you want:

*Main> :t let untilM p f x = if p x then return x else untilM p f =<< f x in untilM let untilM p f x = if p x then return x else untilM p f =<< f x in untilM :: (Monad m) => (a -> Bool) -> (a -> m a) -> a -> m a

  ___________________
(---o-------o-o-o---o-o-o----(
David F. Place
mailto:[EMAIL PROTECTED]




  ___________________
(---o-------o-o-o---o-o-o----(
David F. Place
mailto:[EMAIL PROTECTED]


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to