Control.Error.Script

errors-2.3.0: Simplified error-handling

Safe Haskell | Safe-Inferred
Language | Haskell98

Control.Error.Script

Contents

- The Script Monad

Description

Use this module if you like to write simple scripts with `Text`-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 Text IO
- runScript :: Script a -> IO a
- scriptIO :: forall (m :: Type -> Type) a. MonadIO m => IO a -> ExceptT Text m a

# The Script Monad

type Script = ExceptT Text IO #

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

runScript :: Script a -> IO a #

Runs the `Script` monad

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

scriptIO :: forall (m :: Type -> Type) a. MonadIO m => IO a -> ExceptT Text m a #

`scriptIO` resembles `lift`, except it catches all exceptions and converts them to `Text`

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