errors-1.4.0: Simplified error-handling

Safe HaskellNone




Use this module if you like to write simple scripts with String-based errors, but you prefer to use EitherT 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)


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

scriptIO :: MonadIO m => IO a -> EitherT String m aSource

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

Note that scriptIO is compatible with the Script monad.