errors-2.1.3: Simplified error-handling

Safe Haskell | Safe
Language | Haskell98

Control.Error.Script

Contents

- The Script Monad

Description

Use this module if you like to write simple scripts with `String`-based errors, but you prefer to use `ExceptT` to handle errors rather than `Control.Exception`.

    import Control.Error

    main = runScript $ do
        str <- scriptIO getLine
        n   <- tryRead "Read failed" str
        scriptIO $ print (n + 1)

Synopsis

- type Script = ExceptT String IO
- runScript :: Script a -> IO a
- scriptIO :: MonadIO m => IO a -> ExceptT String m a

# The Script Monad

type Script = ExceptT String IO #

An `IO` action that can fail with a `String` error message

runScript :: Script a -> IO a #

Runs the `Script` monad

Prints the first error to `stderr` and exits with `exitFailure`

scriptIO :: MonadIO m => IO a -> ExceptT String m a #

`scriptIO` resembles `lift`, except it catches all exceptions and converts them to `String`s.

Note that `scriptIO` is compatible with the `Script` monad.