Safe Haskell | None |
---|---|
Language | Haskell2010 |
Example usage:
import Control.Break import Control.Monad.State import Prelude hiding (break) example :: State Int () example = loop (do n <- lift get -- Inside a `loop`, wrap commands in `lift` if n < 10 then lift (put (n + 1)) -- You keep looping by default else break () ) -- Use `break` to exit from the `loop`
The loop
command runs the given command repeatedly until the command breaks
from the loop
using break
:
>>>
execState example 0
10
For some effects (like State
), you can omit lift
:
example :: State Int () example = loop (do n <- get if n < 10 then put (n + 1) else break () )
The loop
will return whatever value you supply to break
:
example :: State Int Bool example = loop (do n <- get if n < 10 then put (n + 1) else break True )
>>>
runState example 0
(True,10)
Break
For the most common use cases you will:
- build
Break
commands usinglift
orbreak
- combine
Break
commands usingdo
notation - consume
Break
commands usingloop
The meaning of the type parameters:
MonadReader d m => MonadReader d (Break r m) Source # | |
MonadState s m => MonadState s (Break r m) Source # | |
MonadWriter w m => MonadWriter w (Break r m) Source # | |
MonadTrans (Break r) Source # | |
Monad m => Monad (Break r m) Source # | |
Functor m => Functor (Break r m) Source # | |
Monad m => Applicative (Break r m) Source # | |
MonadIO m => MonadIO (Break r m) Source # | |
MonadCont m => MonadCont (Break r m) Source # | |
Re-exports
lift :: MonadTrans t => forall m a. Monad m => m a -> t m a #
Lift a computation from the argument monad to the constructed monad.