summaryrefslogtreecommitdiff
path: root/compiler/prelude
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 /compiler/prelude
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 'compiler/prelude')
-rw-r--r--compiler/prelude/PrelRules.hs10
1 files changed, 4 insertions, 6 deletions
diff --git a/compiler/prelude/PrelRules.hs b/compiler/prelude/PrelRules.hs
index 2a174b13fc..13e271bc66 100644
--- a/compiler/prelude/PrelRules.hs
+++ b/compiler/prelude/PrelRules.hs
@@ -656,13 +656,11 @@ instance MonadFail.MonadFail RuleM where
#endif
instance Alternative RuleM where
- empty = mzero
- (<|>) = mplus
+ empty = RuleM $ \_ _ _ -> Nothing
+ RuleM f1 <|> RuleM f2 = RuleM $ \dflags iu args ->
+ f1 dflags iu args <|> f2 dflags iu args
-instance MonadPlus RuleM where
- mzero = RuleM $ \_ _ _ -> Nothing
- mplus (RuleM f1) (RuleM f2) = RuleM $ \dflags iu args ->
- f1 dflags iu args `mplus` f2 dflags iu args
+instance MonadPlus RuleM
instance HasDynFlags RuleM where
getDynFlags = RuleM $ \dflags _ _ -> Just dflags