1 {-# LANGUAGE FlexibleInstances #-}
2 {-# OPTIONS_GHC -fno-warn-tabs #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Lib.Data.Monoid where
6 import Control.Monad (Monad(..), liftM2)
7 import Control.Monad.Trans.State.Strict as ST
8 import Data.Monoid (Monoid(..))
9 import qualified Hcompta.Lib.Control.Monad.Classes as MC
12 -- * Class 'Monoid1' (contain orphan instances)
14 -- | 'Monoid' lifted to unary type constructor.
15 class Monoid1 expr where
16 mempty1 :: Monoid a => expr a
17 mappend1 :: Monoid a => expr a -> expr a -> expr a
18 instance Monoid1 IO where
21 instance (Monoid1 m, Monad m) => Monoid1 (ST.StateT s m) where
24 instance (Monad m, Monoid a) => Monoid (ST.StateT s m a) where
25 mempty = return mempty
26 mappend = liftM2 mappend
27 instance Monoid a => Monoid (IO a) where
28 mempty = return mempty
29 mappend = liftM2 mappend
30 instance (Monoid1 m, Monad m) => Monoid1 (MC.WriterT w m) where
33 instance (Monad m, Monoid a) => Monoid (MC.WriterT w m a) where
34 mempty = return mempty
35 mappend = liftM2 mappend