1
0
forked from GitHub/gf-core

command language and gfcc term parser in bnfc

This commit is contained in:
aarne
2007-11-03 22:00:08 +00:00
parent 7003654ca6
commit f91e19f0d8
9 changed files with 1424 additions and 3 deletions

26
src/GF/Command/ErrM.hs Normal file
View File

@@ -0,0 +1,26 @@
-- BNF Converter: Error Monad
-- Copyright (C) 2004 Author: Aarne Ranta
-- This file comes with NO WARRANTY and may be used FOR ANY PURPOSE.
module GF.Command.ErrM where
-- the Error monad: like Maybe type with error msgs
import Control.Monad (MonadPlus(..), liftM)
data Err a = Ok a | Bad String
deriving (Read, Show, Eq, Ord)
instance Monad Err where
return = Ok
fail = Bad
Ok a >>= f = f a
Bad s >>= f = Bad s
instance Functor Err where
fmap = liftM
instance MonadPlus Err where
mzero = Bad "Err.mzero"
mplus (Bad _) y = y
mplus x _ = x