1
0
forked from GitHub/gf-core

Moved Err definition to GF.Data.ErrM from GF.Data.Operations. This means the GF-embed does not have to include GF.Data.Operations.

This commit is contained in:
bringert
2007-12-20 17:41:31 +00:00
parent 073c217b58
commit d88071c37c
2 changed files with 24 additions and 25 deletions

View File

@@ -12,9 +12,27 @@
-- hack for BNFC generated files. AR 21/9/2003
-----------------------------------------------------------------------------
module GF.Data.ErrM (
module GF.Data.Operations
) where
module GF.Data.ErrM (Err(..)) where
import GF.Data.Operations (Err(..))
import Control.Monad (MonadPlus(..))
-- | like @Maybe@ type with error msgs
data Err a = Ok a | Bad String
deriving (Read, Show, Eq)
instance Monad Err where
return = Ok
fail = Bad
Ok a >>= f = f a
Bad s >>= f = Bad s
-- | added 2\/10\/2003 by PEB
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

View File

@@ -80,6 +80,8 @@ import Data.List (nub, sortBy, sort, deleteBy, nubBy)
--import Data.FiniteMap
import Control.Monad (liftM,liftM2, MonadPlus, mzero, mplus)
import GF.Data.ErrM
infixr 5 +++
infixr 5 ++-
infixr 5 ++++
@@ -94,27 +96,6 @@ onSnd f (x, y) = (x, f y)
-- the Error monad
-- | like @Maybe@ type with error msgs
data Err a = Ok a | Bad String
deriving (Read, Show, Eq)
instance Monad Err where
return = Ok
fail = Bad
Ok a >>= f = f a
Bad s >>= f = Bad s
-- | added 2\/10\/2003 by PEB
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