Skip to content

Commit 9c0cb9c

Browse files
authored
Add Semigroup and Monoid instances (#51)
* Add Semigroup and Monoid instances * Update CHANGELOG.md
1 parent 870f1bc commit 9c0cb9c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Add Semigroup and Monoid instances (#51 by @PureFunctor)
1011

1112
Bugfixes:
1213

src/Control/Monad/ST/Internal.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Control.Monad.ST.Internal
1515

1616
import Prelude
1717

18+
import Control.Apply (lift2)
1819
import Control.Monad.Rec.Class (class MonadRec, Step(..))
1920
import Partial.Unsafe (unsafePartial)
2021

@@ -72,6 +73,12 @@ instance monadRecST :: MonadRec (ST r) where
7273
Loop _ -> true
7374
_ -> false
7475

76+
instance semigroupST :: Semigroup a => Semigroup (ST r a) where
77+
append = lift2 append
78+
79+
instance monoidST :: Monoid a => Monoid (ST r a) where
80+
mempty = pure mempty
81+
7582
-- | Run an `ST` computation.
7683
-- |
7784
-- | Note: the type of `run` uses a rank-2 type to constrain the phantom

0 commit comments

Comments
 (0)