Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ganeti.BasicTypes
Synopsis
- data GenericResult a b
- genericResult :: (a -> c) -> (b -> c) -> GenericResult a b -> c
- type Result = GenericResult String
- newtype ResultT a m b = ResultT {
- runResultT :: m (GenericResult a b)
- mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e m a
- withError :: MonadError e m => (e' -> e) -> GenericResult e' a -> m a
- withErrorT :: (Monad m, Error e) => (e' -> e) -> ResultT e' m a -> ResultT e m a
- toError :: MonadError e m => GenericResult e a -> m a
- toErrorBase :: (MonadBase b m, MonadError e m) => ResultT e b a -> m a
- toErrorStr :: (MonadError e m, Error e) => Result a -> m a
- tryError :: MonadError e m => m a -> m (Either e a)
- class Error e where
- strMsg :: String -> e
- class Monad m => MonadIO (m :: Type -> Type) where
- liftIO :: IO a -> m a
- isOk :: GenericResult a b -> Bool
- isBad :: GenericResult a b -> Bool
- justOk :: [GenericResult a b] -> [b]
- justBad :: [GenericResult a b] -> [a]
- eitherToResult :: Either a b -> GenericResult a b
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- annotateResult :: (MonadError e m, Error e) => String -> Result a -> m a
- annotateError :: (MonadError e m, Error e, Monoid e) => String -> m a -> m a
- failError :: (MonadError e m, Error e) => String -> m a
- catchErrorT :: (Monad m, Error e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m a
- handleErrorT :: (Monad m, Error e) => (e' -> ResultT e m a) -> ResultT e' m a -> ResultT e m a
- orElse :: MonadError e m => m a -> m a -> m a
- iterateOk :: (a -> GenericResult b a) -> a -> [a]
- select :: a -> [(Bool, a)] -> a
- runListHead :: a -> (b -> a) -> [b] -> a
- data LookupResult = LookupResult {
- lrMatchPriority :: MatchPriority
- lrContent :: String
- data MatchPriority
- lookupName :: [String] -> String -> LookupResult
- goodLookupResult :: LookupResult -> Bool
- goodMatchPriority :: MatchPriority -> Bool
- prefixMatch :: String -> String -> Bool
- compareNameComponent :: String -> String -> LookupResult
- newtype ListSet a = ListSet {
- unListSet :: Set a
- emptyListSet :: ListSet a
Documentation
data GenericResult a b #
Generic monad for our error handling mechanisms.
Instances
genericResult :: (a -> c) -> (b -> c) -> GenericResult a b -> c #
Sum type structure of GenericResult.
type Result = GenericResult String #
Type alias for a string Result.
This is a monad transformation for Result. It's implementation is based on the implementations of MaybeT and ErrorT.
ResultT
is very similar to ErrorT
, but with one subtle difference:
If mplus
combines two failing operations, errors of both of them
are combined.
Constructors
ResultT | |
Fields
|
Instances
(Error a, MonadBaseControl IO m) => MonadBaseControl IO (ResultT a m) # | |
Defined in Ganeti.BasicTypes Associated Types type StM (ResultT a m) a | |
(Monad m, Error a) => MonadError a (ResultT a m) # | |
Defined in Ganeti.BasicTypes Methods throwError :: a -> ResultT a m a0 catchError :: ResultT a m a0 -> (a -> ResultT a m a0) -> ResultT a m a0 | |
(MonadBase IO m, Error a) => MonadBase IO (ResultT a m) # | |
Defined in Ganeti.BasicTypes | |
Error a => MonadTransControl (ResultT a) # | |
Error a => MonadTrans (ResultT a) # | |
Defined in Ganeti.BasicTypes | |
(Monad m, Error a) => MonadFail (ResultT a m) # | |
Defined in Ganeti.BasicTypes | |
(MonadIO m, Error a) => MonadIO (ResultT a m) # | The instance catches any This way, monadic code within Other exceptions (see instances of |
Defined in Ganeti.BasicTypes | |
(Monad m, Error a, Monoid a) => Alternative (ResultT a m) # | |
(Applicative m, Monad m, Error a) => Applicative (ResultT a m) # | |
Defined in Ganeti.BasicTypes | |
Functor m => Functor (ResultT a m) # | |
(Monad m, Error a) => Monad (ResultT a m) # | |
(Monad m, Error a, Monoid a) => MonadPlus (ResultT a m) # | |
(MonadLog m, Error e) => MonadLog (ResultT e m) # | |
Defined in Ganeti.Logging | |
type StT (ResultT a) b # | |
Defined in Ganeti.BasicTypes | |
type StM (ResultT a m) b # | |
Defined in Ganeti.BasicTypes |
mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e m a #
Converts a monadic result with a String
message into
a ResultT
with an arbitrary Error
.
Expects that the given action has already taken care of any possible
errors. In particular, if applied on IO (Result a)
, any exceptions
should be handled by the given action.
See also toErrorStr
.
withError :: MonadError e m => (e' -> e) -> GenericResult e' a -> m a #
Changes the error message of a result value, if present.
Note that since GenericResult
is also a MonadError
, this function
is a generalization of
(Error e') => (e' -> e) -> GenericResult e' a -> GenericResult e a
withErrorT :: (Monad m, Error e) => (e' -> e) -> ResultT e' m a -> ResultT e m a #
Changes the error message of a ResultT
value, if present.
toError :: MonadError e m => GenericResult e a -> m a #
toErrorBase :: (MonadBase b m, MonadError e m) => ResultT e b a -> m a #
Lift a ResultT
value into any MonadError
with the same base monad.
toErrorStr :: (MonadError e m, Error e) => Result a -> m a #
An alias for withError strMsg
, which is often used to lift a pure error
to a monad stack. See also annotateResult
.
tryError :: MonadError e m => m a -> m (Either e a) #
Run a given computation and if an error occurs, return it as Left
of
Either
.
This is a generalized version of try
.
Instances
Error IOException # | |
Defined in Ganeti.BasicTypes | |
Error GanetiException # | |
Defined in Ganeti.Errors Methods strMsg :: String -> GanetiException # | |
Error FailMode # |
|
Defined in Ganeti.HTools.Types | |
a ~ Char => Error [a] # | |
Defined in Ganeti.BasicTypes |
class Monad m => MonadIO (m :: Type -> Type) where #
Instances
MonadIO MetadMonadInt # | |
Defined in Ganeti.Metad.ConfigCore Methods liftIO :: IO a -> MetadMonadInt a # | |
MonadIO RpcClientMonad # | |
Defined in Ganeti.THH.HsRPC Methods liftIO :: IO a -> RpcClientMonad a # | |
MonadIO WConfdMonadInt # | |
Defined in Ganeti.WConfd.Monad Methods liftIO :: IO a -> WConfdMonadInt a # | |
MonadIO IO | |
Defined in Control.Monad.IO.Class | |
MonadIO Snap | |
Defined in Snap.Internal.Core | |
MonadIO Q | |
Defined in Language.Haskell.TH.Syntax | |
MonadIO m => MonadIO (WriterLogT m) # | |
Defined in Ganeti.Logging.WriterLog Methods liftIO :: IO a -> WriterLogT m a # | |
MonadIO m => MonadIO (MaybeT m) | |
Defined in Control.Monad.Trans.Maybe | |
(Functor f, MonadIO m) => MonadIO (FreeT f m) | |
Defined in Control.Monad.Trans.Free | |
(MonadIO m, Error a) => MonadIO (ResultT a m) # | The instance catches any This way, monadic code within Other exceptions (see instances of |
Defined in Ganeti.BasicTypes | |
(Monoid w, Functor m, MonadIO m) => MonadIO (AccumT w m) | |
Defined in Control.Monad.Trans.Accum | |
MonadIO m => MonadIO (ExceptT e m) | |
Defined in Control.Monad.Trans.Except | |
MonadIO m => MonadIO (IdentityT m) | |
Defined in Control.Monad.Trans.Identity | |
MonadIO m => MonadIO (ReaderT r m) | |
Defined in Control.Monad.Trans.Reader | |
MonadIO m => MonadIO (SelectT r m) | |
Defined in Control.Monad.Trans.Select | |
MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Lazy | |
MonadIO m => MonadIO (StateT s m) | |
Defined in Control.Monad.Trans.State.Strict | |
MonadIO m => MonadIO (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.CPS | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Lazy | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
Defined in Control.Monad.Trans.Writer.Strict | |
MonadIO m => MonadIO (ContT r m) | |
Defined in Control.Monad.Trans.Cont | |
MonadIO m => MonadIO (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.CPS | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Lazy | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
Defined in Control.Monad.Trans.RWS.Strict |
isOk :: GenericResult a b -> Bool #
Simple checker for whether a GenericResult
is OK.
isBad :: GenericResult a b -> Bool #
Simple checker for whether a GenericResult
is a failure.
justOk :: [GenericResult a b] -> [b] #
Simple filter returning only OK values of GenericResult
justBad :: [GenericResult a b] -> [a] #
Simple filter returning only Bad values of GenericResult
eitherToResult :: Either a b -> GenericResult a b #
Converter from Either to GenericResult
.
isLeft :: Either a b -> Bool #
Check if an either is Left. Equivalent to isLeft from Data.Either version 4.7.0.0 or higher.
isRight :: Either a b -> Bool #
Check if an either is Right. Equivalent to isRight from Data.Either version 4.7.0.0 or higher.
annotateResult :: (MonadError e m, Error e) => String -> Result a -> m a #
Annotate an error with an ownership information, lifting it to a
MonadError
. Since Result
is an instance of MonadError
itself,
it's a generalization of type String -> Result a -> Result a
.
See also toErrorStr
.
annotateError :: (MonadError e m, Error e, Monoid e) => String -> m a -> m a #
Annotate an error with an ownership information inside a MonadError
.
See also annotateResult
.
failError :: (MonadError e m, Error e) => String -> m a #
Throws a String
message as an error in a MonadError
.
This is a generalization of Bad
.
It's similar to fail
, but works within a MonadError
, avoiding the
unsafe nature of fail
.
catchErrorT :: (Monad m, Error e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m a #
Catches an error in a ResultT
value. This is similar to catchError
,
but in addition allows to change the error type.
handleErrorT :: (Monad m, Error e) => (e' -> ResultT e m a) -> ResultT e' m a -> ResultT e m a #
A synonym for flip
catchErrorT
.
orElse :: MonadError e m => m a -> m a -> m a #
If the first computation fails, run the second one.
Unlike mplus
instance for ResultT
, this doesn't require
the Monoid
constrait.
iterateOk :: (a -> GenericResult b a) -> a -> [a] #
Iterate while Ok.
Arguments
:: a | default result |
-> [(Bool, a)] | list of "condition, result" |
-> a | first result which has a True condition, or default |
Return the first result with a True condition, or the default otherwise.
runListHead :: a -> (b -> a) -> [b] -> a #
Apply a function to the first element of a list, return the default value, if the list is empty. This is just a convenient combination of maybe and listToMaybe.
data LookupResult #
The result of a name lookup in a list.
Constructors
LookupResult | |
Fields
|
Instances
Show LookupResult # | |
Defined in Ganeti.BasicTypes Methods showsPrec :: Int -> LookupResult -> ShowS show :: LookupResult -> String showList :: [LookupResult] -> ShowS | |
Eq LookupResult # | Lookup results have an absolute preference ordering. |
Defined in Ganeti.BasicTypes | |
Ord LookupResult # | |
Defined in Ganeti.BasicTypes Methods compare :: LookupResult -> LookupResult -> Ordering (<) :: LookupResult -> LookupResult -> Bool (<=) :: LookupResult -> LookupResult -> Bool (>) :: LookupResult -> LookupResult -> Bool (>=) :: LookupResult -> LookupResult -> Bool max :: LookupResult -> LookupResult -> LookupResult min :: LookupResult -> LookupResult -> LookupResult |
data MatchPriority #
The priority of a match in a lookup result.
Constructors
ExactMatch | |
MultipleMatch | |
PartialMatch | |
FailMatch |
Instances
Arguments
:: [String] | List of keys |
-> String | Lookup string |
-> LookupResult | Result of the lookup |
Find the canonical name for a lookup string in a list of names.
goodLookupResult :: LookupResult -> Bool #
Is the lookup result an actual match?
goodMatchPriority :: MatchPriority -> Bool #
Is the lookup priority a "good" one?
Arguments
:: String | Lookup |
-> String | Full name |
-> Bool | Whether there is a prefix match |
Check for prefix matches in names. Implemented in Ganeti core utils.text.MatchNameComponent as the regexp r"^%s(..*)?$" % re.escape(key)
Arguments
:: String | Canonical (target) name |
-> String | Partial (lookup) name |
-> LookupResult | Result of the lookup |
Compares a canonical name and a lookup string.
Wrapper for a Haskell Set
This type wraps a Set
and it is used in the Haskell to Python
opcode generation to transform a Haskell Set
into a Python list
without duplicate elements.
emptyListSet :: ListSet a #