
20 May
2007
20 May
'07
2:54 a.m.
matt:
It occurred to me that the predicate will generally be a monadic function itself, so here's a refined version:
:: Monad m => (a -> m Bool) -> (a -> m a) -> a -> m a untilM pred f x = do c <- pred x if c then return x else f x >>= untilM pred f
Here's a cute example of a loop from xmonad: fix $ \again -> do more <- checkMaskEvent d enterWindowMask p when more again But maybe Spencer was just being funny when he wrote that. -- Don