diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2016-01-01 01:45:08 +0100 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2016-01-01 01:55:16 +0100 |
commit | dafeb51f266793a67e8ae18ae39a2e2e87943824 (patch) | |
tree | f1ef3abd7fc655e6b8896a6841f0efd9a39a39fe /libraries/base/Text | |
parent | 8afeaad919dc67643b4eff14efafb48b59039b2b (diff) | |
download | haskell-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/Text')
-rw-r--r-- | libraries/base/Text/ParserCombinators/ReadP.hs | 12 | ||||
-rw-r--r-- | libraries/base/Text/ParserCombinators/ReadPrec.hs | 8 |
2 files changed, 7 insertions, 13 deletions
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 |