Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- type ErrIO = ExceptT Text IO
- type ErrOrVal = Either Text
- toErrOrVal :: Either String a -> ErrOrVal a
- runErr :: ErrIO a -> IO (ErrOrVal a)
- runErrorVoid :: ErrIO () -> IO ()
- undef :: Text -> a
- fromRightEOV :: ErrOrVal a -> a
- bracketErrIO :: ErrIO a -> (a -> ErrIO b) -> (a -> ErrIO c) -> ErrIO c
- callIO :: IO a -> ErrIO a
- throwErrorWords :: [Text] -> ErrIO a
- throwErrorT :: Text -> ErrIO a
- catchError :: Monad m => ExceptT e m a -> (e -> ExceptT e' m a) -> ExceptT e' m a
- maybe2error :: Maybe a -> ErrIO a
- errorT :: [Text] -> a
- errorWords :: [Text] -> a
- fromJustNoteT :: [Text] -> Maybe a -> a
- fromRightNoteString :: Text -> Either String b -> b
- fromRightNote :: Text -> Either Text b -> b
- headNoteT :: [Text] -> [a] -> a
- startProg :: Show a => Text -> ErrIO a -> IO ()
- readNote :: (Partial, Read a) => String -> String -> a
- headNote :: Partial => String -> [a] -> a
- module Control.Monad
- module Control.Monad.Trans.Except
- liftIO :: MonadIO m => IO a -> m a
- class Monad m => MonadIO (m :: Type -> Type)
- data SomeException
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
fromRightEOV :: ErrOrVal a -> a Source #
throwErrorWords :: [Text] -> ErrIO a Source #
throwErrorT :: Text -> ErrIO a Source #
maybe2error :: Maybe a -> ErrIO a Source #
errorWords :: [Text] -> a Source #
fromJustNoteT :: [Text] -> Maybe a -> a Source #
readNote :: (Partial, Read a) => String -> String -> a #
readNote
uses readEitherSafe
for the error message.
module Control.Monad
module Control.Monad.Trans.Except
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
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
, we would have ended up with this error:liftIO
• 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
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> 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:
Instances
MonadIO IO | Since: base-4.9.0.0 |
Defined in Control.Monad.IO.Class | |
MonadIO Snap | |
Defined in Snap.Internal.Core | |
MonadIO Q | |
Defined in Language.Haskell.TH.Syntax | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
Defined in Control.Monad.Trans.Error | |
MonadIO m => MonadIO (ExceptT e m) | |
Defined in Control.Monad.Trans.Except |
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
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type | |
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # |