This package provides imperative-style loops supporting "continue" and
"break".  For example:

    import Control.Monad
    import Control.Monad.IO.Class
    import Control.Monad.Trans.Loop
    import Control.Monad.Trans.Class

    main :: IO ()
    main =
        foreach [0..] $ \i ->
        foreach [0..] $ \j -> do
            when (j == 0) $
                continue    -- skip to next iteration
            when (j >= 5) $
                exit        -- exit the loop
            when (i >= 5) $
                lift exit   -- exit the outer loop by calling 'exit'
in the parent monad
            liftIO $ print (i, j)

It works by having the loop body run under the LoopT monad
transformer, which provides early exit functions 'continue' and
'exit'.  Functions like 'foreach' and 'while' run a LoopT callback,
passing it continuations defining 'continue' and 'exit'.

http://hackage.haskell.org/package/control-monad-loop

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

Reply via email to