Commit 25779212 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add an Applicative instance for our Result type



This will allow us to run generic computations in an Applicative
context, if a monadic one is not needed (or not applicable due to
class constraints).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 05ac718f
......@@ -36,6 +36,7 @@ module Ganeti.BasicTypes
, compareNameComponent
) where
import Control.Applicative
import Control.Monad
import Data.Function
import Data.List
......@@ -68,6 +69,12 @@ instance MonadPlus Result where
(Bad _) `mplus` x = x
x@(Ok _) `mplus` _ = x
instance Applicative Result where
pure = Ok
(Bad f) <*> _ = Bad f
_ <*> (Bad x) = Bad x
(Ok f) <*> (Ok x) = Ok $ f x
-- | Simple checker for whether a 'Result' is OK.
isOk :: Result a -> Bool
isOk (Ok _) = True
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment