[Haskell-cafe] Exceptions

Dominic Steinitz dominic.steinitz at blueyonder.co.uk
Sat Oct 2 04:20:37 EDT 2004


I'd be cautious about using exceptions too liberally. When I implemented 
a Haskell equivalent to traceroute, I wanted to stop sending packets 
when a certain condition occurred. It was very tempting to throw an 
exception and catch it at the top level. However, I think the code below 
is easier for the maintainer (me) to understand.

Dominic.

sequenceWhile_ :: Monad m => (a -> Bool) -> [m a] -> m ()
sequenceWhile_ p [] =
   return ()
sequenceWhile_ p (x:xs) =
   x >>= \c -> if (p c) then sequenceWhile_ p xs else return ()



More information about the Haskell-Cafe mailing list