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`

:

`>>>`

10`execState example 0`

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 )

`>>>`

(True,10)`runState example 0`

# Break

For the most common use cases you will:

MonadState s m => MonadState s (Break r m) | |

MonadWriter w m => MonadWriter w (Break r m) | |

MonadTrans (Break r) | |

Monad m => Monad (Break r m) | |

Functor m => Functor (Break r m) | |

(Monad m, Functor m) => Applicative (Break r m) | |

MonadIO m => MonadIO (Break r m) | |

MonadCont m => MonadCont (Break r m) |

# 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.