
module Utility (module Control.Error, catchIO, foldML, strictIO) where

import Control.Error
import Control.Monad

catchIO :: IO a -> EitherT String IO a
catchIO a = tryIO a `catchT` (left . show)

foldML :: Monad m => [a -> m a] -> a -> m a
foldML = foldl (>=>) return

-- | Run an application with an error possibility. Terminate the
--   application with the error message or exit gracefully
strictIO :: Monad m => EitherT String m a -> m a
strictIO = eitherT error return