Safe Haskell | Safe-Infered |
---|
- 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)
- elimResultT :: Monad m => (a -> ResultT a' m b') -> (b -> ResultT a' m b') -> ResultT a m b -> ResultT a' m b'
- 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
- resultT :: Monad m => GenericResult a b -> ResultT a m b
- toErrorStr :: (MonadError e m, Error e) => Result a -> m a
- mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e 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
- annotateResult :: String -> Result a -> Result a
- annotateError :: (MonadError e m, Error e, Monoid e) => String -> m a -> m a
- failError :: (MonadError e m, Error e) => String -> m a
- handleErrorT :: (Monad m, Error e) => (e' -> ResultT e m a) -> ResultT e' m a -> ResultT e m a
- catchErrorT :: (Monad m, Error e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m a
- iterateOk :: (a -> GenericResult b a) -> a -> [a]
- select :: a -> [(Bool, a)] -> a
- runListHead :: a -> (b -> a) -> [b] -> a
- data MatchPriority
- = ExactMatch
- | MultipleMatch
- | PartialMatch
- | FailMatch
- data LookupResult = LookupResult {
- lrMatchPriority :: MatchPriority
- lrContent :: String
- prefixMatch :: String -> String -> Bool
- goodMatchPriority :: MatchPriority -> Bool
- goodLookupResult :: LookupResult -> Bool
- compareNameComponent :: String -> String -> LookupResult
- chooseLookupResult :: String -> String -> LookupResult -> LookupResult
- lookupName :: [String] -> String -> LookupResult
- newtype ListSet a = ListSet {
- unListSet :: Set a
- emptyListSet :: ListSet a
Documentation
data GenericResult a b Source
Generic monad for our error handling mechanisms.
Error a => MonadError a (GenericResult a) | |
Error a => Monad (GenericResult a) |
|
Functor (GenericResult a) | |
(Error a, Monoid a) => MonadPlus (GenericResult a) | |
Applicative (GenericResult a) | |
(Error a, Monoid a) => Alternative (GenericResult a) | |
Arbitrary a => Arbitrary (Result a) | |
Arbitrary a => Arbitrary (OpResult a) | |
(Eq a, Eq b) => Eq (GenericResult a b) | |
(Show a, Show b) => Show (GenericResult a b) |
genericResult :: (a -> c) -> (b -> c) -> GenericResult a b -> cSource
Sum type structure of GenericResult.
type Result = GenericResult StringSource
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.
ResultT | |
|
(Monad m, Error a) => MonadError a (ResultT a m) | |
MonadTrans (ResultT a) | |
(Monad m, Error a) => Monad (ResultT a m) | |
Monad f => Functor (ResultT a f) | |
(Monad m, Error a, Monoid a) => MonadPlus (ResultT a m) | |
(Monad m, Error a) => Applicative (ResultT a m) | |
(Monad m, Error a, Monoid a) => Alternative (ResultT a m) | |
(MonadIO m, Error a) => MonadIO (ResultT a m) |
elimResultT :: Monad m => (a -> ResultT a' m b') -> (b -> ResultT a' m b') -> ResultT a m b -> ResultT a' m b'Source
withError :: MonadError e m => (e' -> e) -> GenericResult e' a -> m aSource
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 aSource
Changes the error message of a ResultT
value, if present.
toErrorStr :: (MonadError e m, Error e) => Result a -> m aSource
An alias for withError strMsg
, which is often used to lift a pure error
to a monad stack. See also annotateResult
.
mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e m aSource
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
.
isOk :: GenericResult a b -> BoolSource
Simple checker for whether a GenericResult
is OK.
isBad :: GenericResult a b -> BoolSource
Simple checker for whether a GenericResult
is a failure.
justOk :: [GenericResult a b] -> [b]Source
Simple filter returning only OK values of GenericResult
justBad :: [GenericResult a b] -> [a]Source
Simple filter returning only Bad values of GenericResult
eitherToResult :: Either a b -> GenericResult a bSource
Converter from Either to GenericResult
.
annotateResult :: String -> Result a -> Result aSource
annotateError :: (MonadError e m, Error e, Monoid e) => String -> m a -> m aSource
Annotate an error with an ownership information inside a MonadError
.
See also annotateResult
.
failError :: (MonadError e m, Error e) => String -> m aSource
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
.
handleErrorT :: (Monad m, Error e) => (e' -> ResultT e m a) -> ResultT e' m a -> ResultT e m aSource
A synonym for flip
catchErrorT
.
catchErrorT :: (Monad m, Error e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m aSource
Catches an error in a ResultT
value. This is similar to catchError
,
but in addition allows to change the error type.
iterateOk :: (a -> GenericResult b a) -> a -> [a]Source
Iterate while Ok.
Misc functionality
:: 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] -> aSource
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.
Lookup of partial names functionality
data MatchPriority Source
The priority of a match in a lookup result.
Enum MatchPriority | |
Eq MatchPriority | |
Ord MatchPriority | |
Show MatchPriority |
data LookupResult Source
The result of a name lookup in a list.
LookupResult | |
|
Eq LookupResult | Lookup results have an absolute preference ordering. |
Ord LookupResult | |
Show LookupResult |
:: 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)
goodMatchPriority :: MatchPriority -> BoolSource
Is the lookup priority a good one?
goodLookupResult :: LookupResult -> BoolSource
Is the lookup result an actual match?
:: String | Canonical (target) name |
-> String | Partial (lookup) name |
-> LookupResult | Result of the lookup |
Compares a canonical name and a lookup string.
chooseLookupResult :: String -> String -> LookupResult -> LookupResultSource
:: [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.
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.