errors-2.2.4: Simplified error-handling

Safe HaskellSafe
LanguageHaskell98

Control.Error.Script

Contents

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

The Script Monad

type Script = ExceptT Text IO Source #

An IO action that can fail with a Text error message

runScript :: Script a -> IO a Source #

Runs the Script monad

Prints the first error to stderr and exits with exitFailure

scriptIO :: MonadIO m => IO a -> ExceptT Text m a Source #

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

Note that scriptIO is compatible with the Script monad.