module Data.Monoid.Instances () where
#ifdef M_MTL
import Control.Monad.Reader
import qualified Control.Monad.RWS.Lazy as LRWS
import qualified Control.Monad.RWS.Strict as SRWS
import qualified Control.Monad.State.Lazy as LState
import qualified Control.Monad.State.Strict as SState
import Control.Monad.Writer
import qualified Control.Monad.Writer.Strict as SWriter
#endif
#ifdef X_OverloadedStrings
import Data.String
#endif
import Data.Bits
import Data.Ratio
#ifdef M_FINGERTREE
import Data.FingerTree
#endif
#ifdef M_PARSEC
import Text.Parsec.Prim
#endif
#ifdef M_MTL
instance (MonadPlus m, Monoid w) => Monoid (SWriter.WriterT w m n) where
mempty = mzero
mappend = mplus
instance (MonadPlus m, Monoid w) => Monoid (WriterT w m n) where
mempty = mzero
mappend = mplus
instance (MonadPlus m, Monoid w) => Monoid (SRWS.RWST r w s m n) where
mempty = mzero
mappend = mplus
instance (MonadPlus m, Monoid w) => Monoid (LRWS.RWST r w s m n) where
mempty = mzero
mappend = mplus
instance MonadPlus m => Monoid (ReaderT e m n) where
mempty = mzero
mappend = mplus
instance MonadPlus m => Monoid (SState.StateT s m n) where
mempty = mzero
mappend = mplus
instance MonadPlus m => Monoid (LState.StateT s m n) where
mempty = mzero
mappend = mplus
#endif
#ifdef M_FINGERTREE
instance Measured v a => Monoid (FingerTree v a) where
mempty = empty
mappend = (><)
#endif
#ifdef M_PARSEC
instance Stream s m t => Monoid (ParsecT s u m a) where
mempty = mzero
a `mappend` b = try a <|> b
#endif
#ifdef X_OverloadedStrings
instance (IsString a, IsString b) => IsString (a,b) where
fromString a = (fromString a, fromString a)
instance (IsString a, IsString b, IsString c) => IsString (a,b,c) where
fromString a = (fromString a, fromString a, fromString a)
instance (IsString a, IsString b, IsString c, IsString d) => IsString (a,b,c,d) where
fromString a = (fromString a, fromString a, fromString a, fromString a)
instance (IsString a, IsString b, IsString c, IsString d, IsString e) => IsString (a,b,c,d,e) where
fromString a = (fromString a, fromString a, fromString a, fromString a, fromString a)
#endif
instance Monoid Int where
mempty = 0
mappend = (+)
instance Monoid Integer where
mempty = 0
mappend = (+)
instance Integral m => Monoid (Ratio m) where
mempty = 0
mappend = (+)
instance Monoid Bool where
mempty = 0
mappend = (||)
instance Num Bool where
(+) = (||)
(*) = (&&)
x y = x && not y
negate = not
abs = id
signum = id
fromInteger 0 = False
fromInteger _ = True
instance Bits Bool where
(.&.) = (&&)
(.|.) = (||)
xor True True = False
xor False False = False
xor _ _ = True
complement = not
shiftL a b = a && (b == 0)
shiftR a b = a && (b == 0)
shift a b = a && (b == 0)
rotate a _ = a
bit = (==0)
setBit a b = a || (b == 0)
testBit a b = a && (b == 0)
bitSize _ = 1
isSigned _ = False