errors-2.1.3: Simplified error-handling

Safe HaskellSafe
LanguageHaskell98

Control.Error.Script

Contents

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

The Script Monad

type Script = ExceptT String IO Source #

An IO action that can fail with a String 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 String m a Source #

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

Note that scriptIO is compatible with the Script monad.