[Haskell-cafe] [Haskell] ANNOUNCE: control-monad-loop 0.1

Roman Cheplyaka roma at ro-che.info
Mon Jul 9 14:28:21 CEST 2012


* Joey Adams <joeyadams3.14159 at gmail.com> [2012-07-09 01:38:06-0400]
> 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)

Very nice!

Here's a patch to generalize foreach to any Foldable:
https://github.com/joeyadams/haskell-control-monad-loop/pull/1

Also, it's not obvious how your tests work. Please consider using HUnit
and test-framework (or similar) to organize them.

-- 
Roman I. Cheplyaka :: http://ro-che.info/



More information about the Haskell-Cafe mailing list