[Haskell-cafe] How do I do conditional tail recursion in a monad?
David F. Place
d at vidplace.com
Wed Mar 21 08:18:58 EDT 2007
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.
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:d at vidplace.com
More information about the Haskell-Cafe
mailing list