diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2015-10-08 16:34:17 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2015-10-10 15:10:29 +0200 |
commit | db60084d738621b13835af2444bdf8c50013bf65 (patch) | |
tree | 431850660b8bb1472c4ca43c3407c446101bd37d /libraries/base/Control | |
parent | f64f7c36ef9395da1cc7b686aaf1b019204cd0fc (diff) | |
download | haskell-wip/D1316.tar.gz |
base: MRP-refactoring of AMP instanceswip/D1316
Summary:
This refactors (>>)/(*>)/return/pure methods into normalform.
The redundant explicit `return` method definitions are dropped
altogether.
This results in measurable runtime improvements in nofib of up
to -20% runtime (geometric mean: -7%) in my measurements.
Reviewers: quchen, austin, alanz, bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1316
Diffstat (limited to 'libraries/base/Control')
-rw-r--r-- | libraries/base/Control/Applicative.hs | 2 | ||||
-rw-r--r-- | libraries/base/Control/Arrow.hs | 1 | ||||
-rw-r--r-- | libraries/base/Control/Monad/ST/Lazy/Imp.hs | 4 |
3 files changed, 2 insertions, 5 deletions
diff --git a/libraries/base/Control/Applicative.hs b/libraries/base/Control/Applicative.hs index a2f342f83f..6770234926 100644 --- a/libraries/base/Control/Applicative.hs +++ b/libraries/base/Control/Applicative.hs @@ -96,7 +96,7 @@ instance Monad m => Functor (WrappedMonad m) where fmap f (WrapMonad v) = WrapMonad (liftM f v) instance Monad m => Applicative (WrappedMonad m) where - pure = WrapMonad . return + pure = WrapMonad . pure WrapMonad f <*> WrapMonad v = WrapMonad (f `ap` v) instance MonadPlus m => Alternative (WrappedMonad m) where diff --git a/libraries/base/Control/Arrow.hs b/libraries/base/Control/Arrow.hs index 9d09544eeb..c9281569f9 100644 --- a/libraries/base/Control/Arrow.hs +++ b/libraries/base/Control/Arrow.hs @@ -314,7 +314,6 @@ instance Arrow a => Applicative (ArrowMonad a) where ArrowMonad f <*> ArrowMonad x = ArrowMonad (f &&& x >>> arr (uncurry id)) instance ArrowApply a => Monad (ArrowMonad a) where - return x = ArrowMonad (arr (\_ -> x)) ArrowMonad m >>= f = ArrowMonad $ m >>> arr (\x -> let ArrowMonad h = f x in (h, ())) >>> app diff --git a/libraries/base/Control/Monad/ST/Lazy/Imp.hs b/libraries/base/Control/Monad/ST/Lazy/Imp.hs index 55b28cfc9a..c99912e62d 100644 --- a/libraries/base/Control/Monad/ST/Lazy/Imp.hs +++ b/libraries/base/Control/Monad/ST/Lazy/Imp.hs @@ -71,13 +71,11 @@ instance Functor (ST s) where (f r,new_s) instance Applicative (ST s) where - pure = return + pure a = ST $ \ s -> (a,s) (<*>) = ap instance Monad (ST s) where - return a = ST $ \ s -> (a,s) - m >> k = m >>= \ _ -> k fail s = error s (ST m) >>= k |