summaryrefslogtreecommitdiff
path: root/compiler/utils/IOEnv.hs
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/utils/IOEnv.hs
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/utils/IOEnv.hs')
-rw-r--r--compiler/utils/IOEnv.hs14
1 files changed, 5 insertions, 9 deletions
diff --git a/compiler/utils/IOEnv.hs b/compiler/utils/IOEnv.hs
index 4470420a64..6c081ea3d0 100644
--- a/compiler/utils/IOEnv.hs
+++ b/compiler/utils/IOEnv.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE DeriveDataTypeable, UndecidableInstances #-}
+{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE CPP #-}
--
@@ -177,15 +177,11 @@ uninterruptibleMaskM_ (IOEnv m) = IOEnv (\ env -> uninterruptibleMask_ (m env))
-- Alternative/MonadPlus
----------------------------------------------------------------------
-instance MonadPlus IO => Alternative (IOEnv env) where
- empty = mzero
- (<|>) = mplus
+instance Alternative (IOEnv env) where
+ empty = IOEnv (const empty)
+ m <|> n = IOEnv (\env -> unIOEnv m env <|> unIOEnv n env)
--- For use if the user has imported Control.Monad.Error from MTL
--- Requires UndecidableInstances
-instance MonadPlus IO => MonadPlus (IOEnv env) where
- mzero = IOEnv (const mzero)
- m `mplus` n = IOEnv (\env -> unIOEnv m env `mplus` unIOEnv n env)
+instance MonadPlus (IOEnv env)
----------------------------------------------------------------------
-- Accessing input/output