summaryrefslogtreecommitdiff
path: root/libraries/base
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2016-01-01 01:45:08 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2016-01-01 01:55:16 +0100
commitdafeb51f266793a67e8ae18ae39a2e2e87943824 (patch)
treef1ef3abd7fc655e6b8896a6841f0efd9a39a39fe /libraries/base
parent8afeaad919dc67643b4eff14efafb48b59039b2b (diff)
downloadhaskell-dafeb51f266793a67e8ae18ae39a2e2e87943824.tar.gz
Canonicalise `MonadPlus` instances
This refactoring exploits the fact that since AMP, in most cases, `instance MonadPlus` can be automatically derived from the respective `Alternative` instance. This is because `MonadPlus`'s default method implementations are fully defined in terms of `Alternative(empty, (<>))`.
Diffstat (limited to 'libraries/base')
-rw-r--r--libraries/base/Control/Arrow.hs4
-rw-r--r--libraries/base/Data/Semigroup.hs4
-rw-r--r--libraries/base/GHC/Conc/Sync.hs4
-rw-r--r--libraries/base/Text/ParserCombinators/ReadP.hs12
-rw-r--r--libraries/base/Text/ParserCombinators/ReadPrec.hs8
5 files changed, 10 insertions, 22 deletions
diff --git a/libraries/base/Control/Arrow.hs b/libraries/base/Control/Arrow.hs
index 3417f30cc1..9fc2ee5c90 100644
--- a/libraries/base/Control/Arrow.hs
+++ b/libraries/base/Control/Arrow.hs
@@ -321,9 +321,7 @@ instance ArrowPlus a => Alternative (ArrowMonad a) where
empty = ArrowMonad zeroArrow
ArrowMonad x <|> ArrowMonad y = ArrowMonad (x <+> y)
-instance (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a) where
- mzero = ArrowMonad zeroArrow
- ArrowMonad x `mplus` ArrowMonad y = ArrowMonad (x <+> y)
+instance (ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)
-- | Any instance of 'ArrowApply' can be made into an instance of
-- 'ArrowChoice' by defining 'left' = 'leftApp'.
diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs
index 6fa0cd85d6..518e215661 100644
--- a/libraries/base/Data/Semigroup.hs
+++ b/libraries/base/Data/Semigroup.hs
@@ -592,9 +592,7 @@ instance Alternative Option where
Option Nothing <|> b = b
a <|> _ = a
-instance MonadPlus Option where
- mzero = Option Nothing
- mplus = (<|>)
+instance MonadPlus Option
instance MonadFix Option where
mfix f = Option (mfix (getOption . f))
diff --git a/libraries/base/GHC/Conc/Sync.hs b/libraries/base/GHC/Conc/Sync.hs
index e1d894a8c1..2a5164b798 100644
--- a/libraries/base/GHC/Conc/Sync.hs
+++ b/libraries/base/GHC/Conc/Sync.hs
@@ -659,9 +659,7 @@ instance Alternative STM where
empty = retry
(<|>) = orElse
-instance MonadPlus STM where
- mzero = empty
- mplus = (<|>)
+instance MonadPlus STM
-- | Unsafely performs IO in the STM monad. Beware: this is a highly
-- dangerous thing to do.
diff --git a/libraries/base/Text/ParserCombinators/ReadP.hs b/libraries/base/Text/ParserCombinators/ReadP.hs
index 6c340e4597..8b84acf24e 100644
--- a/libraries/base/Text/ParserCombinators/ReadP.hs
+++ b/libraries/base/Text/ParserCombinators/ReadP.hs
@@ -108,9 +108,7 @@ instance Applicative P where
pure x = Result x Fail
(<*>) = ap
-instance MonadPlus P where
- mzero = empty
- mplus = (<|>)
+instance MonadPlus P
instance Monad P where
(Get f) >>= k = Get (\c -> f c >>= k)
@@ -175,12 +173,10 @@ instance MonadFail ReadP where
fail _ = R (\_ -> Fail)
instance Alternative ReadP where
- empty = mzero
- (<|>) = mplus
+ empty = pfail
+ (<|>) = (+++)
-instance MonadPlus ReadP where
- mzero = pfail
- mplus = (+++)
+instance MonadPlus ReadP
-- ---------------------------------------------------------------------------
-- Operations over P
diff --git a/libraries/base/Text/ParserCombinators/ReadPrec.hs b/libraries/base/Text/ParserCombinators/ReadPrec.hs
index 136b8aed00..2a9c1d0fe8 100644
--- a/libraries/base/Text/ParserCombinators/ReadPrec.hs
+++ b/libraries/base/Text/ParserCombinators/ReadPrec.hs
@@ -87,13 +87,11 @@ instance Monad ReadPrec where
instance MonadFail.MonadFail ReadPrec where
fail s = P (\_ -> fail s)
-instance MonadPlus ReadPrec where
- mzero = pfail
- mplus = (+++)
+instance MonadPlus ReadPrec
instance Alternative ReadPrec where
- empty = mzero
- (<|>) = mplus
+ empty = pfail
+ (<|>) = (+++)
-- precedences
type Prec = Int