Skip to content

Commit 1073966

Browse files
committed
monad-stm: added Semigroup and Monoid instances
1 parent 6b81d7c commit 1073966

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

io-classes/src/Control/Monad/Class/MonadSTM/Internal.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,12 @@ deriving instance MonadSTM m => Monad (WrappedSTM t r m)
13191319
deriving instance MonadSTM m => Alternative (WrappedSTM t r m)
13201320
deriving instance MonadSTM m => MonadPlus (WrappedSTM t r m)
13211321

1322+
instance ( Semigroup a, MonadSTM m ) => Semigroup (WrappedSTM t r m a) where
1323+
a <> b = (<>) <$> a <*> b
1324+
instance ( Monoid a , MonadSTM m ) => Monoid (WrappedSTM t r m a) where
1325+
mempty = pure mempty
1326+
1327+
13221328
-- note: this (and the following) instance requires 'UndecidableInstances'
13231329
-- extension because it violates 3rd Paterson condition, however `STM m` will
13241330
-- resolve to a concrete type of kind (Type -> Type), and thus no larger than

io-sim/src/Control/Monad/IOSim/Types.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ data SimA s a where
178178

179179
newtype STM s a = STM { unSTM :: forall r. (a -> StmA s r) -> StmA s r }
180180

181+
instance Semigroup a => Semigroup (STM s a) where
182+
a <> b = (<>) <$> a <*> b
183+
184+
instance Monoid a => Monoid (STM s a) where
185+
mempty = pure mempty
186+
181187
runSTM :: STM s a -> StmA s a
182188
runSTM (STM k) = k ReturnStm
183189

0 commit comments

Comments
 (0)