Commit 441c52de authored by Ben Gamari's avatar Ben Gamari 🐢
Browse files

Add Semigroup/Monoid instances to ST monad

Fixes #14107

.
Signed-off-by: default avatarPhilipp Middendorf <middendorf@plapadoo.de>

Reviewers: austin, hvr, bgamari, RyanGlScott

Reviewed By: bgamari

Subscribers: RyanGlScott, rwbarton, thomie

GHC Trac Issues: #14107

Differential Revision: https://phabricator.haskell.org/D3845
parent a520adcc
......@@ -72,6 +72,7 @@ import Prelude hiding (foldr1)
import Control.Applicative
import Control.Monad
import Control.Monad.Fix
import Control.Monad.ST(ST)
import Data.Bifoldable
import Data.Bifunctor
import Data.Bitraversable
......@@ -725,6 +726,10 @@ instance Semigroup (Proxy s) where
instance Semigroup a => Semigroup (IO a) where
(<>) = liftA2 (<>)
-- | @since 4.11.0.0
instance Semigroup a => Semigroup (ST s a) where
(<>) = liftA2 (<>)
#if !defined(mingw32_HOST_OS)
-- | @since 4.10.0.0
instance Semigroup Event where
......
......@@ -77,6 +77,11 @@ instance Monad (ST s) where
case (k r) of { ST k2 ->
(k2 new_s) }})
-- | @since 4.11.0.0
instance Monoid a => Monoid (ST s a) where
mempty = pure mempty
mappend = liftA2 mappend
data STret s a = STret (State# s) a
-- liftST is useful when we want a lifted result from an ST computation. See
......
......@@ -14,6 +14,8 @@
* Remove the deprecated `Typeable{1..7}` type synonyms (#14047)
* Add instances `Semigroup` and `Monoid` for `Control.Monad.ST` (#14107).
## 4.10.0.0 *April 2017*
* Bundled with GHC *TBA*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment