Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data App a
- runApp :: MonadIO m => Env -> App a -> m a
- runTestApp :: Key a -> a -> App b -> IO b
- askApp :: App AppConfig
- askAttr :: Key a -> App (Maybe a)
- withAttr :: Key a -> a -> App b -> App b
- requireAttr :: Key a -> App a
- data AppConfig = AppConfig {}
- data Env = Env {}
- getAttr :: Key a -> Env -> Maybe a
- reqAttr :: Default a => Key a -> Env -> a
- setAttr :: Key a -> a -> Env -> Env
- randomString :: IO ByteString
- showText :: Show a => a -> Text
- throwS :: (HasCallStack, MonadIO m, MonadLogger m) => ServantErr -> Text -> m a
- randomCode :: Vector Char -> Int -> IO String
- whenException :: SomeException -> Response
- type LogFunc = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
- class Default a where
- def :: a
- data Text
- pack :: String -> Text
- type HasCallStack = ?callStack :: CallStack
- class Monad m => MonadError e (m :: Type -> Type) | m -> e where
- throwError :: e -> m a
- catchError :: m a -> (e -> m a) -> m a
- class MonadIO m => MonadUnliftIO (m :: Type -> Type) where
- askUnliftIO :: m (UnliftIO m)
- withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b
- data SomeException where
- SomeException :: forall e. Exception e => e -> SomeException
- fromException :: Exception e => SomeException -> Maybe e
- bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
- throw :: Exception e => e -> a
- try :: Exception e => IO a -> IO (Either e a)
- catch :: Exception e => IO a -> (e -> IO a) -> IO a
- (<>) :: Semigroup a => a -> a -> a
- module Data.Proxy
- type Vault = Vault RealWorld
- newKey :: IO (Key a)
- type Key = Key RealWorld
- module Data.Maybe
- module Data.Word
- encodeUtf8 :: Text -> ByteString
- decodeUtf8 :: ByteString -> Text
- module Data.Function
- module Data.Version
- module Control.Applicative
- module Control.Monad
- module Control.Monad.Reader
- module Control.Monad.Logger.CallStack
- module Network.Wai
- module Network.HTTP.Types
App Monad
Instances
Monad App Source # | |
Functor App Source # | |
Applicative App Source # | |
MonadIO App Source # | |
MonadUnliftIO App Source # | |
HasValid App Source # | |
MonadLogger App Source # | |
MonadLoggerIO App Source # | |
MonadTracing App Source # | |
MonadTracer App Source # | |
Defined in Yam.Middleware.Trace askSpanContext :: App SpanContext Source # | |
MonadReader Env App Source # | |
requireAttr :: Key a -> App a Source #
Environment
Env | |
|
Utilities
randomString :: IO ByteString Source #
Utility
throwS :: (HasCallStack, MonadIO m, MonadLogger m) => ServantErr -> Text -> m a Source #
Reexport Functions
A class for types with a default value.
Nothing
Instances
A space efficient, packed, unboxed Unicode text type.
Instances
type HasCallStack = ?callStack :: CallStack #
Request a CallStack.
NOTE: The implicit parameter ?callStack :: CallStack
is an
implementation detail and should not be considered part of the
CallStack
API, we may decide to change the implementation in the
future.
Since: base-4.9.0.0
class Monad m => MonadError e (m :: Type -> Type) | m -> e where #
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use
as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the Either
StringMonadError
class.
You can also define your own error type and/or use a monad type constructor
other than
or Either
String
.
In these cases you will have to explicitly define instances of the Either
IOError
MonadError
class.
(If you are using the deprecated Control.Monad.Error or
Control.Monad.Trans.Error, you may also have to define an Error
instance.)
throwError :: e -> m a #
Is used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m a #
A handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handler
where the action
functions can call throwError
.
Note that handler
and the do-block must have the same return type.
Instances
class MonadIO m => MonadUnliftIO (m :: Type -> Type) where #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
The third is a currently nameless law which ensures that the current context is preserved.
askUnliftIO >>= (u -> liftIO (unliftIO u m)) = m
If you have a name for this, please submit it in a pull request for great glory.
Since: unliftio-core-0.1.0.0
askUnliftIO :: m (UnliftIO m) #
Capture the current monadic context, providing the ability to
run monadic actions in IO
.
See UnliftIO
for an explanation of why we need a helper
datatype here.
Since: unliftio-core-0.1.0.0
withRunInIO :: ((forall a. m a -> IO a) -> IO b) -> m b #
Convenience function for capturing the monadic context and running an IO
action with a runner function. The runner function is used to run a monadic
action m
in IO
.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO App Source # | |
MonadUnliftIO m => MonadUnliftIO (ResourceT m) | Since: resourcet-1.1.10 |
Defined in Control.Monad.Trans.Resource.Internal | |
MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger askUnliftIO :: NoLoggingT m (UnliftIO (NoLoggingT m)) # withRunInIO :: ((forall a. NoLoggingT m a -> IO a) -> IO b) -> NoLoggingT m b # | |
MonadUnliftIO m => MonadUnliftIO (LoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
data SomeException where #
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
.
SomeException :: forall e. Exception e => e -> SomeException |
Instances
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type |
fromException :: Exception e => SomeException -> Maybe e #
:: IO a | computation to run first ("acquire resource") |
-> (a -> IO b) | computation to run last ("release resource") |
-> (a -> IO c) | computation to run in-between |
-> IO c |
When you want to acquire a resource, do some work with it, and
then release the resource, it is a good idea to use bracket
,
because bracket
will install the necessary exception handler to
release the resource in the event that an exception is raised
during the computation. If an exception is raised, then bracket
will
re-raise the exception (after performing the release).
A common example is opening a file:
bracket (openFile "filename" ReadMode) (hClose) (\fileHandle -> do { ... })
The arguments to bracket
are in this order so that we can partially apply
it, e.g.:
withFile name mode = bracket (openFile name mode) hClose
throw :: Exception e => e -> a #
Throw an exception. Exceptions may be thrown from purely
functional code, but may only be caught within the IO
monad.
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)
:: Exception e | |
=> IO a | The computation to run |
-> (e -> IO a) | Handler to invoke if an exception is raised |
-> IO a |
This is the simplest of the exception-catching functions. It takes a single argument, runs it, and if an exception is raised the "handler" is executed, with the value of the exception passed as an argument. Otherwise, the result is returned as normal. For example:
catch (readFile f) (\e -> do let err = show (e :: IOException) hPutStr stderr ("Warning: Couldn't open " ++ f ++ ": " ++ err) return "")
Note that we have to give a type signature to e
, or the program
will not typecheck as the type is ambiguous. While it is possible
to catch exceptions of any type, see the section "Catching all
exceptions" (in Control.Exception) for an explanation of the problems with doing so.
For catching exceptions in pure (non-IO
) expressions, see the
function evaluate
.
Note that due to Haskell's unspecified evaluation order, an
expression may throw one of several possible exceptions: consider
the expression (error "urk") + (1 `div` 0)
. Does
the expression throw
ErrorCall "urk"
, or DivideByZero
?
The answer is "it might throw either"; the choice is
non-deterministic. If you are catching any type of exception then you
might catch either. If you are calling catch
with type
IO Int -> (ArithException -> IO Int) -> IO Int
then the handler may
get run with DivideByZero
as an argument, or an ErrorCall "urk"
exception may be propogated further up. If you call it again, you
might get a the opposite behaviour. This is ok, because catch
is an
IO
computation.
module Data.Proxy
type Vault = Vault RealWorld #
A persistent store for values of arbitrary types.
This variant is the simplest and creates keys in the IO
monad.
See the module Data.Vault.ST if you want to use it with the ST
monad instead.
module Data.Maybe
module Data.Word
encodeUtf8 :: Text -> ByteString #
Encode text using UTF-8 encoding.
decodeUtf8 :: ByteString -> Text #
Decode a ByteString
containing UTF-8 encoded text that is known
to be valid.
If the input contains any invalid UTF-8 data, an exception will be
thrown that cannot be caught in pure code. For more control over
the handling of invalid data, use decodeUtf8'
or
decodeUtf8With
.
module Data.Function
module Data.Version
module Control.Applicative
module Control.Monad
module Control.Monad.Reader
module Network.Wai
module Network.HTTP.Types