uniform-error-0.1.5.1: Handling errors in the uniform framework
Safe HaskellSafe-Inferred
LanguageHaskell2010

Uniform.Error

Synopsis

Documentation

runErr :: ErrIO a -> IO (ErrOrVal a) Source #

runErr to avoid the depreceated message for runErrorT, which is identical

runErrorVoid :: ErrIO () -> IO () Source #

run an operation in ErrIO which is not returning anything simpler to use than runErr

undef :: Text -> a Source #

for type specification, not to be evaluated

bracketErrIO Source #

Arguments

:: ErrIO a

computation to run first ("acquire resource")

-> (a -> ErrIO b)

computation to run last ("release resource")

-> (a -> ErrIO c)

computation to run in-between

-> ErrIO c 

callIO :: IO a -> ErrIO a Source #

this is using catch to grab all errors

catchError :: Monad m => ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a Source #

errorT :: [Text] -> a Source #

a list of texts is output with failure

headNoteT :: [Text] -> [a] -> a Source #

startProg :: Show a => Text -> ErrIO a -> IO () Source #

readNote :: (Partial, Read a) => String -> String -> a #

readNote uses readEitherSafe for the error message.

headNote :: Partial => String -> [a] -> a #

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

Example

Expand
import Control.Monad.Trans.State -- from the "transformers" library

printState :: Show s => StateT s IO ()
printState = do
  state <- get
  liftIO $ print state

Had we omitted liftIO, we would have ended up with this error:

• Couldn't match type ‘IO’ with ‘StateT s IO’
 Expected type: StateT s IO ()
   Actual type: IO ()

The important part here is the mismatch between StateT s IO () and IO ().

Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3

class Monad m => MonadIO (m :: Type -> Type) #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Minimal complete definition

liftIO

Instances

Instances details
MonadIO IO

Since: base-4.9.0.0

Instance details

Defined in Control.Monad.IO.Class

Methods

liftIO :: IO a -> IO a #

MonadIO Snap 
Instance details

Defined in Snap.Internal.Core

Methods

liftIO :: IO a -> Snap a #

MonadIO Q 
Instance details

Defined in Language.Haskell.TH.Syntax

Methods

liftIO :: IO a -> Q a #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 
Instance details

Defined in Control.Monad.Trans.Error

Methods

liftIO :: IO a -> ErrorT e m a #

MonadIO m => MonadIO (ExceptT e m) 
Instance details

Defined in Control.Monad.Trans.Except

Methods

liftIO :: IO a -> ExceptT e m a #

data SomeException #

The SomeException type is the root of the exception type hierarchy. When an exception of type e is thrown, behind the scenes it is encapsulated in a SomeException.

Instances

Instances details
Exception SomeException

Since: base-3.0

Instance details

Defined in GHC.Exception.Type

Show SomeException

Since: base-3.0

Instance details

Defined in GHC.Exception.Type

Orphan instances

CharChains2 IOError Text Source # 
Instance details

Methods

show' :: IOError -> Text #