summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Base.hs
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2015-10-08 16:34:17 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2015-10-10 15:10:29 +0200
commitdb60084d738621b13835af2444bdf8c50013bf65 (patch)
tree431850660b8bb1472c4ca43c3407c446101bd37d /libraries/base/GHC/Base.hs
parentf64f7c36ef9395da1cc7b686aaf1b019204cd0fc (diff)
downloadhaskell-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/GHC/Base.hs')
-rw-r--r--libraries/base/GHC/Base.hs18
1 files changed, 7 insertions, 11 deletions
diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 9bd6124e6a..273950b1fb 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -309,7 +309,6 @@ instance Monoid a => Applicative ((,) a) where
(u, f) <*> (v, x) = (u `mappend` v, f x)
instance Monoid a => Monad ((,) a) where
- return x = (mempty, x)
(u, a) >>= k = case k a of (v, b) -> (u `mappend` v, b)
instance Monoid a => Monoid (IO a) where
@@ -626,7 +625,6 @@ instance Applicative ((->) a) where
(<*>) f g x = f x (g x)
instance Monad ((->) r) where
- return = const
f >>= k = \ r -> k (f r) r
instance Functor ((,) a) where
@@ -652,7 +650,6 @@ instance Monad Maybe where
(>>) = (*>)
- return = Just
fail _ = Nothing
-- -----------------------------------------------------------------------------
@@ -735,8 +732,6 @@ instance Monad [] where
xs >>= f = [y | x <- xs, y <- f x]
{-# INLINE (>>) #-}
(>>) = (*>)
- {-# INLINE return #-}
- return x = [x]
{-# INLINE fail #-}
fail _ = []
@@ -1063,18 +1058,19 @@ asTypeOf = const
----------------------------------------------
instance Functor IO where
- fmap f x = x >>= (return . f)
+ fmap f x = x >>= (pure . f)
instance Applicative IO where
- pure = return
- (<*>) = ap
+ {-# INLINE pure #-}
+ {-# INLINE (*>) #-}
+ pure = returnIO
+ m *> k = m >>= \ _ -> k
+ (<*>) = ap
instance Monad IO where
- {-# INLINE return #-}
{-# INLINE (>>) #-}
{-# INLINE (>>=) #-}
- m >> k = m >>= \ _ -> k
- return = returnIO
+ (>>) = (*>)
(>>=) = bindIO
fail s = failIO s