diff --git a/htools/Ganeti/HTools/Types.hs b/htools/Ganeti/HTools/Types.hs index 6452f5b6d6efa2582085d875eff7ee0860443da9..ec774b012af344b0351017497e5b86fda57d97dd 100644 --- a/htools/Ganeti/HTools/Types.hs +++ b/htools/Ganeti/HTools/Types.hs @@ -67,6 +67,7 @@ module Ganeti.HTools.Types , EvacMode(..) ) where +import Control.Monad import qualified Data.Map as M import qualified Text.JSON as JSON @@ -272,6 +273,14 @@ instance Monad Result where return = Ok fail = Bad +instance MonadPlus Result where + mzero = Bad "zero Result when used as MonadPlus" + -- for mplus, when we 'add' two Bad values, we concatenate their + -- error descriptions + (Bad x) `mplus` (Bad y) = Bad (x ++ "; " ++ y) + (Bad _) `mplus` x = x + x@(Ok _) `mplus` _ = x + -- | Simple checker for whether a 'Result' is OK. isOk :: Result a -> Bool isOk (Ok _) = True