]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/Lib/Data/Monoid.hs
Simplify hcompta-lib.
[comptalang.git] / cli / Hcompta / Lib / Data / Monoid.hs
1 {-# LANGUAGE FlexibleInstances #-}
2 {-# OPTIONS_GHC -fno-warn-tabs #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Lib.Data.Monoid where
5
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
10 import System.IO (IO)
11
12 -- * Class 'Monoid1' (contain orphan instances)
13
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
19 mempty1 = mempty
20 mappend1 = mappend
21 instance (Monoid1 m, Monad m) => Monoid1 (ST.StateT s m) where
22 mempty1 = mempty
23 mappend1 = mappend
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
31 mempty1 = mempty
32 mappend1 = mappend
33 instance (Monad m, Monoid a) => Monoid (MC.WriterT w m a) where
34 mempty = return mempty
35 mappend = liftM2 mappend
36