errors-1.0.0: Simplified error-handling

Safe HaskellSafe-Infered

Control.Error.Script

Contents

Description

Use this module if you like to write simple scripts, but you prefer to use EitherT to handle errors rather than Control.Exception.

 import Control.Error

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

Synopsis

The Script Monad

type Script = EitherT String IOSource

An IO action that can fail with a String error message

runScript :: Script a -> IO aSource

Runs the Script monad

Prints the first error to stderr and exits with exitFailure

tryMaybe :: String -> Maybe a -> Script aSource

A Maybe that fails in the Script monad

tryEither :: Either String r -> Script rSource

An Either that fails in the Script monad

tryIO :: IO a -> Script aSource

tryIO is like lift, except it converts exceptions to the Script monad