ganeti
Safe HaskellSafe

Ganeti.BasicTypes

Synopsis

Documentation

data GenericResult a b Source #

Generic monad for our error handling mechanisms.

Constructors

Bad a 
Ok b 

Instances

Instances details
Error a => MonadError a (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

throwError :: a -> GenericResult a a0

catchError :: GenericResult a a0 -> (a -> GenericResult a a0) -> GenericResult a a0

Error a => Monad (GenericResult a) #

Monad instance for GenericResult.

Instance details

Defined in Ganeti.BasicTypes

Methods

(>>=) :: GenericResult a a0 -> (a0 -> GenericResult a b) -> GenericResult a b

(>>) :: GenericResult a a0 -> GenericResult a b -> GenericResult a b

return :: a0 -> GenericResult a a0

Functor (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

fmap :: (a0 -> b) -> GenericResult a a0 -> GenericResult a b

(<$) :: a0 -> GenericResult a b -> GenericResult a a0

Error a => MonadFail (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

fail :: String -> GenericResult a a0

Applicative (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

pure :: a0 -> GenericResult a a0

(<*>) :: GenericResult a (a0 -> b) -> GenericResult a a0 -> GenericResult a b

liftA2 :: (a0 -> b -> c) -> GenericResult a a0 -> GenericResult a b -> GenericResult a c

(*>) :: GenericResult a a0 -> GenericResult a b -> GenericResult a b

(<*) :: GenericResult a a0 -> GenericResult a b -> GenericResult a a0

(Error a, Monoid a) => Alternative (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

empty :: GenericResult a a0

(<|>) :: GenericResult a a0 -> GenericResult a a0 -> GenericResult a a0

some :: GenericResult a a0 -> GenericResult a [a0]

many :: GenericResult a a0 -> GenericResult a [a0]

(Error a, Monoid a) => MonadPlus (GenericResult a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

mzero :: GenericResult a a0

mplus :: GenericResult a a0 -> GenericResult a a0 -> GenericResult a a0

Arbitrary a => Arbitrary (Result a) 
Instance details

Defined in Test.Ganeti.BasicTypes

Methods

arbitrary :: Gen (Result a)

shrink :: Result a -> [Result a]

Arbitrary a => Arbitrary (OpResult a) 
Instance details

Defined in Test.Ganeti.HTools.Types

Methods

arbitrary :: Gen (OpResult a)

shrink :: OpResult a -> [OpResult a]

(Eq a, Eq b) => Eq (GenericResult a b) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

(==) :: GenericResult a b -> GenericResult a b -> Bool

(/=) :: GenericResult a b -> GenericResult a b -> Bool

(Show a, Show b) => Show (GenericResult a b) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

showsPrec :: Int -> GenericResult a b -> ShowS

show :: GenericResult a b -> String

showList :: [GenericResult a b] -> ShowS

genericResult :: (a -> c) -> (b -> c) -> GenericResult a b -> c Source #

Sum type structure of GenericResult.

type Result = GenericResult String Source #

Type alias for a string Result.

newtype ResultT a m b Source #

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

Instances details
(MonadBase IO m, Error a) => MonadBase IO (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

liftBase :: IO α -> ResultT a m α

(Monad m, Error a) => MonadError a (ResultT a m) # 
Instance details

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

(Error a, MonadBaseControl IO m) => MonadBaseControl IO (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Associated Types

type StM (ResultT a m) a

Methods

liftBaseWith :: (RunInBase (ResultT a m) IO -> IO a0) -> ResultT a m a0

restoreM :: StM (ResultT a m) a0 -> ResultT a m a0

MonadTrans (ResultT a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

lift :: Monad m => m a0 -> ResultT a m a0

Error a => MonadTransControl (ResultT a) # 
Instance details

Defined in Ganeti.BasicTypes

Associated Types

type StT (ResultT a) a

Methods

liftWith :: Monad m => (Run (ResultT a) -> m a0) -> ResultT a m a0

restoreT :: Monad m => m (StT (ResultT a) a0) -> ResultT a m a0

(Monad m, Error a) => Monad (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

(>>=) :: ResultT a m a0 -> (a0 -> ResultT a m b) -> ResultT a m b

(>>) :: ResultT a m a0 -> ResultT a m b -> ResultT a m b

return :: a0 -> ResultT a m a0

Functor m => Functor (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

fmap :: (a0 -> b) -> ResultT a m a0 -> ResultT a m b

(<$) :: a0 -> ResultT a m b -> ResultT a m a0

(Monad m, Error a) => MonadFail (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

fail :: String -> ResultT a m a0

(Applicative m, Monad m, Error a) => Applicative (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

pure :: a0 -> ResultT a m a0

(<*>) :: ResultT a m (a0 -> b) -> ResultT a m a0 -> ResultT a m b

liftA2 :: (a0 -> b -> c) -> ResultT a m a0 -> ResultT a m b -> ResultT a m c

(*>) :: ResultT a m a0 -> ResultT a m b -> ResultT a m b

(<*) :: ResultT a m a0 -> ResultT a m b -> ResultT a m a0

(Monad m, Error a, Monoid a) => Alternative (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

empty :: ResultT a m a0

(<|>) :: ResultT a m a0 -> ResultT a m a0 -> ResultT a m a0

some :: ResultT a m a0 -> ResultT a m [a0]

many :: ResultT a m a0 -> ResultT a m [a0]

(Monad m, Error a, Monoid a) => MonadPlus (ResultT a m) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

mzero :: ResultT a m a0

mplus :: ResultT a m a0 -> ResultT a m a0 -> ResultT a m a0

(MonadIO m, Error a) => MonadIO (ResultT a m) #

The instance catches any IOError using try and converts it into an error message using strMsg.

This way, monadic code within ResultT that uses solely liftIO to include IO actions ensures that all IO exceptions are handled.

Other exceptions (see instances of Exception) are not currently handled. This might be revised in the future.

Instance details

Defined in Ganeti.BasicTypes

Methods

liftIO :: IO a0 -> ResultT a m a0

(MonadLog m, Error e) => MonadLog (ResultT e m) # 
Instance details

Defined in Ganeti.Logging

Methods

logAt :: Priority -> String -> ResultT e m () Source #

type StT (ResultT a) b # 
Instance details

Defined in Ganeti.BasicTypes

type StT (ResultT a) b = GenericResult a b
type StM (ResultT a m) b # 
Instance details

Defined in Ganeti.BasicTypes

type StM (ResultT a m) b = ComposeSt (ResultT a) m b

elimResultT :: Monad m => (a -> ResultT a' m b') -> (b -> ResultT a' m b') -> ResultT a m b -> ResultT a' m b' Source #

Eliminates a ResultT value given appropriate continuations

withError :: MonadError e m => (e' -> e) -> GenericResult e' a -> m a Source #

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 Source #

Changes the error message of a ResultT value, if present.

toError :: MonadError e m => GenericResult e a -> m a Source #

Lift a Result value to any MonadError. Since ResultT is itself its instance, it's a generalization of Monad m => GenericResult a b -> ResultT a m b.

toErrorBase :: (MonadBase b m, MonadError e m) => ResultT e b a -> m a Source #

Lift a ResultT value into any MonadError with the same base monad.

toErrorStr :: (MonadError e m, Error e) => Result a -> m a Source #

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) Source #

Run a given computation and if an error occurs, return it as Left of Either. This is a generalized version of try.

mkResultT :: (Monad m, Error e) => m (Result a) -> ResultT e m a Source #

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 -> Bool Source #

Simple checker for whether a GenericResult is OK.

isBad :: GenericResult a b -> Bool Source #

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 b Source #

Converter from Either to GenericResult.

isLeft :: Either a b -> Bool Source #

Check if an either is Left. Equivalent to isLeft from Data.Either version 4.7.0.0 or higher.

isRight :: Either a b -> Bool Source #

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 Source #

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 Source #

Annotate an error with an ownership information inside a MonadError. See also annotateResult.

failError :: (MonadError e m, Error e) => String -> m a Source #

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 a Source #

A synonym for flip catchErrorT.

catchErrorT :: (Monad m, Error e) => ResultT e' m a -> (e' -> ResultT e m a) -> ResultT e m a Source #

Catches an error in a ResultT value. This is similar to catchError, but in addition allows to change the error type.

orElse :: MonadError e m => m a -> m a -> m a Source #

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] Source #

Iterate while Ok.

Misc functionality

select Source #

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 Source #

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 LookupResult Source #

The result of a name lookup in a list.

Constructors

LookupResult 

Fields

Instances

Instances details
Eq LookupResult #

Lookup results have an absolute preference ordering.

Instance details

Defined in Ganeti.BasicTypes

Methods

(==) :: LookupResult -> LookupResult -> Bool

(/=) :: LookupResult -> LookupResult -> Bool

Ord LookupResult # 
Instance details

Defined in Ganeti.BasicTypes

Show LookupResult # 
Instance details

Defined in Ganeti.BasicTypes

Methods

showsPrec :: Int -> LookupResult -> ShowS

show :: LookupResult -> String

showList :: [LookupResult] -> ShowS

prefixMatch Source #

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)

goodMatchPriority :: MatchPriority -> Bool Source #

Is the lookup priority a "good" one?

goodLookupResult :: LookupResult -> Bool Source #

Is the lookup result an actual match?

compareNameComponent Source #

Arguments

:: String

Canonical (target) name

-> String

Partial (lookup) name

-> LookupResult

Result of the lookup

Compares a canonical name and a lookup string.

chooseLookupResult Source #

Arguments

:: String

Lookup key

-> String

String to compare to the lookup key

-> LookupResult

Previous result

-> LookupResult

New result

Lookup a string and choose the best result.

lookupName Source #

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.

newtype ListSet a Source #

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.

Constructors

ListSet 

Fields

Instances

Instances details
Eq a => Eq (ListSet a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

(==) :: ListSet a -> ListSet a -> Bool

(/=) :: ListSet a -> ListSet a -> Bool

Ord a => Ord (ListSet a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

compare :: ListSet a -> ListSet a -> Ordering

(<) :: ListSet a -> ListSet a -> Bool

(<=) :: ListSet a -> ListSet a -> Bool

(>) :: ListSet a -> ListSet a -> Bool

(>=) :: ListSet a -> ListSet a -> Bool

max :: ListSet a -> ListSet a -> ListSet a

min :: ListSet a -> ListSet a -> ListSet a

Show a => Show (ListSet a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

showsPrec :: Int -> ListSet a -> ShowS

show :: ListSet a -> String

showList :: [ListSet a] -> ShowS

(Ord a, JSON a) => JSON (ListSet a) # 
Instance details

Defined in Ganeti.BasicTypes

Methods

readJSON :: JSValue -> Result (ListSet a)

showJSON :: ListSet a -> JSValue

readJSONs :: JSValue -> Result [ListSet a]

showJSONs :: [ListSet a] -> JSValue

PyValue a => PyValue (ListSet a) # 
Instance details

Defined in Ganeti.PyValue

Methods

showValue :: ListSet a -> String Source #

showValueList :: [ListSet a] -> String Source #