Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type Answer a = Either SomeException a
- done :: Monad m => m ()
- (#) :: a -> (a -> b) -> b
- propagate :: Answer a -> IO a
- try :: Exception e => IO a -> IO (Either e a)
- tryUntilOK :: IO a -> IO a
- raise :: IOError -> IO a
- when :: Applicative f => Bool -> f () -> f ()
- unless :: Applicative f => Bool -> f () -> f ()
- incase :: Maybe a -> (a -> IO b) -> IO ()
- forever :: Applicative f => f a -> f b
- foreverUntil :: Monad m => m Bool -> m ()
- foreach :: Monad m => [a] -> (a -> m b) -> m ()
- while :: Monad m => m a -> (a -> Bool) -> m a
- type Config w = w -> IO w
- configure :: w -> [Config w] -> IO w
- config :: IO () -> Config w
- class HasConfig option configuration where
- ($$) :: option -> configuration -> configuration
- configUsed :: option -> configuration -> Bool
- data WithError a
- hasError :: String -> WithError a
- hasValue :: a -> WithError a
- fromWithError :: WithError a -> Either String a
- fromWithError1 :: a -> WithError a -> a
- toWithError :: Either String a -> WithError a
- isError :: WithError a -> Bool
- mapWithError :: (a -> b) -> WithError a -> WithError b
- mapWithError' :: (a -> WithError b) -> WithError a -> WithError b
- mapWithErrorIO :: (a -> IO b) -> WithError a -> IO (WithError b)
- mapWithErrorIO' :: (a -> IO (WithError b)) -> WithError a -> IO (WithError b)
- pairWithError :: WithError a -> WithError b -> WithError (a, b)
- listWithError :: [WithError a] -> WithError [a]
- coerceWithError :: WithError a -> a
- coerceWithErrorIO :: WithError a -> IO a
- coerceWithErrorStringIO :: String -> WithError a -> IO a
- coerceWithErrorOrBreakIOPrefix :: String -> (String -> a) -> WithError a -> IO a
- coerceWithErrorOrBreakPrefix :: String -> (String -> a) -> WithError a -> a
- newtype MonadWithError m a = MonadWithError (m (WithError a))
- monadifyWithError :: Monad m => WithError a -> MonadWithError m a
- toMonadWithError :: Monad m => m a -> MonadWithError m a
- coerceWithErrorOrBreak :: (String -> a) -> WithError a -> a
- coerceWithErrorOrBreakIO :: (String -> a) -> WithError a -> IO a
- concatWithError :: [WithError a] -> WithError [a]
- swapIOWithError :: WithError (IO a) -> IO (WithError a)
- exceptionToError :: Exception e => (e -> Maybe String) -> IO a -> IO (WithError a)
Documentation
type Answer a = Either SomeException a Source #
exceptions and handlers
try :: Exception e => IO a -> IO (Either e a) #
Similar to catch
, but returns an Either
result which is
(
if no exception of type Right
a)e
was raised, or (
if an exception of type Left
ex)e
was raised and its value is ex
.
If any other type of exception is raised than it will be propogated
up to the next enclosing exception handler.
try a = catch (Right `liftM` a) (return . Left)
tryUntilOK :: IO a -> IO a Source #
selectors
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
iterators
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Using ApplicativeDo
: '
' can be understood as the
pseudo-forever
asdo
expression
do as as ..
with as
repeating.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, and channels
(e.g. MVar
and
Chan
).
For example, here is how we might implement an echo
server, using
forever
both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever
$ do client <- accept socketforkFinally
(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever
$ hGetLine client >>= hPutStrLn client
foreverUntil :: Monad m => m Bool -> m () Source #
configure command
The new-style configuration command
Returning results or error messages.
fromWithError1 :: a -> WithError a -> a Source #
mapWithError :: (a -> b) -> WithError a -> WithError b Source #
listWithError :: [WithError a] -> WithError [a] Source #
coerceWithError :: WithError a -> a Source #
coerceWithErrorIO :: WithError a -> IO a Source #
coerceWithErrorOrBreakIOPrefix :: String -> (String -> a) -> WithError a -> IO a Source #
coerce or use the supplied break function (to be used with
addFallOut
)
The first argument is prepended to any error message. The value is evaluated immediately.
coerceWithErrorOrBreakPrefix :: String -> (String -> a) -> WithError a -> a Source #
coerce or use the supplied break function (to be used with
addFallOut
)
The first argument is prepended to any error message.
newtype MonadWithError m a Source #
MonadWithError (m (WithError a)) |
Instances
monadifyWithError :: Monad m => WithError a -> MonadWithError m a Source #
toMonadWithError :: Monad m => m a -> MonadWithError m a Source #
coerceWithErrorOrBreak :: (String -> a) -> WithError a -> a Source #
coerce or use the supplied break function (to be used with
addFallOut
)
coerceWithErrorOrBreakIO :: (String -> a) -> WithError a -> IO a Source #
coerce or use the supplied break function (to be used with
addFallOut
)
The value is evaluated immediately.
concatWithError :: [WithError a] -> WithError [a] Source #