From a9ccc950c60d8d3bc48b80fbb6af8a6118d3bff0 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 19 Aug 2012 01:48:54 +0200 Subject: [PATCH] Add a Functor instance for our Result type This will allow us to use the simpler applicative form (<$>, <*>) instead of monadic liftM, liftM2, etc. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Agata Murawska <agatamurawska@google.com> --- htools/Ganeti/BasicTypes.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htools/Ganeti/BasicTypes.hs b/htools/Ganeti/BasicTypes.hs index 55bab2858..d68387e9e 100644 --- a/htools/Ganeti/BasicTypes.hs +++ b/htools/Ganeti/BasicTypes.hs @@ -56,6 +56,10 @@ instance Monad Result where return = Ok fail = Bad +instance Functor Result where + fmap _ (Bad msg) = Bad msg + fmap fn (Ok val) = Ok (fn val) + instance MonadPlus Result where mzero = Bad "zero Result when used as MonadPlus" -- for mplus, when we 'add' two Bad values, we concatenate their -- GitLab