From a061ad4ee00718949bd15d9076ef8341758d10a1 Mon Sep 17 00:00:00 2001 From: krijo Date: Mon, 14 Mar 2005 22:45:36 +0000 Subject: [PATCH] Err is now an instance of MonadPlus. --- src/GF/Data/Operations.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/GF/Data/Operations.hs b/src/GF/Data/Operations.hs index d1a6562c8..551b0f1aa 100644 --- a/src/GF/Data/Operations.hs +++ b/src/GF/Data/Operations.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/02/24 11:46:35 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.16 $ +-- > CVS $Date: 2005/03/14 23:45:36 $ +-- > CVS $Author: krijo $ +-- > CVS $Revision: 1.17 $ -- -- some auxiliary GF operations. AR 19\/6\/1998 -- 6\/2\/2001 -- @@ -77,7 +77,7 @@ module Operations (-- * misc functions import Char (isSpace, toUpper, isSpace, isDigit) import List (nub, sortBy, sort, deleteBy, nubBy) -import Monad (liftM2) +import Monad (liftM2, MonadPlus, mzero, mplus) infixr 5 +++ infixr 5 ++- @@ -107,6 +107,12 @@ instance Functor Err where fmap f (Ok a) = Ok (f a) fmap f (Bad s) = Bad s +-- | added by KJ +instance MonadPlus Err where + mzero = Bad "error (no reason given)" + mplus (Ok a) _ = Ok a + mplus (Bad s) b = b + -- | analogue of @maybe@ err :: (String -> b) -> (a -> b) -> Err a -> b err d f e = case e of