summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Semigroup.hs
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2015-10-12 11:36:01 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2015-10-12 11:36:12 +0200
commite737a5126dcfdd0610587d2ec16bea6481cf2a42 (patch)
tree03b5a0730980021ea72741bc63818e90b10090d0 /libraries/base/Data/Semigroup.hs
parent4bd58c179b8d0f8cf2850acb920cef8605826a2a (diff)
downloadhaskell-e737a5126dcfdd0610587d2ec16bea6481cf2a42.tar.gz
base: MRP-refactoring of AMP instances
This refactors `(>>)`/`(*>)`/`return`/`pure` methods into normal form. The redundant explicit `return` method definitions are dropped altogether. The explicit `(>>) = (*>)` definitions can't be removed yet, as the default implementation of `(>>)` is still in terms of `(*>)` (even though that should have been changed according to the AMP but wasn't -- see note in GHC.Base for details why this had to be postponed) A nofib comparision shows this refactoring to result in minor runtime improvements (unless those are within normal measurement fluctuations): Program Size Allocs Runtime Elapsed TotalMem ------------------------------------------------------------------------- Min -0.0% -0.0% -1.6% -3.9% -1.1% Max -0.0% +0.0% +0.5% +0.5% 0.0% Geometric Mean -0.0% -0.0% -0.4% -0.5% -0.0% Full `nofib` report at https://phabricator.haskell.org/P68 Reviewers: quchen, alanz, austin, #core_libraries_committee, bgamari Reviewed By: bgamari Differential Revision: https://phabricator.haskell.org/D1316
Diffstat (limited to 'libraries/base/Data/Semigroup.hs')
-rw-r--r--libraries/base/Data/Semigroup.hs21
1 files changed, 8 insertions, 13 deletions
diff --git a/libraries/base/Data/Semigroup.hs b/libraries/base/Data/Semigroup.hs
index 661e513cba..f3f9f0b326 100644
--- a/libraries/base/Data/Semigroup.hs
+++ b/libraries/base/Data/Semigroup.hs
@@ -332,8 +332,7 @@ instance Applicative Min where
Min f <*> Min x = Min (f x)
instance Monad Min where
- return = Min
- _ >> a = a
+ (>>) = (*>)
Min a >>= f = f a
instance MonadFix Min where
@@ -389,8 +388,7 @@ instance Applicative Max where
Max f <*> Max x = Max (f x)
instance Monad Max where
- return = Max
- _ >> a = a
+ (>>) = (*>)
Max a >>= f = f a
instance MonadFix Max where
@@ -476,8 +474,7 @@ instance Applicative First where
First f <*> First x = First (f x)
instance Monad First where
- return = First
- _ >> a = a
+ (>>) = (*>)
First a >>= f = f a
instance MonadFix First where
@@ -523,8 +520,7 @@ instance Applicative Last where
Last f <*> Last x = Last (f x)
instance Monad Last where
- return = Last
- _ >> a = a
+ (>>) = (*>)
Last a >>= f = f a
instance MonadFix Last where
@@ -584,14 +580,13 @@ instance Applicative Option where
pure a = Option (Just a)
Option a <*> Option b = Option (a <*> b)
-instance Monad Option where
- return = pure
+ Option Nothing *> _ = Option Nothing
+ _ *> b = b
+instance Monad Option where
Option (Just a) >>= k = k a
_ >>= _ = Option Nothing
-
- Option Nothing >> _ = Option Nothing
- _ >> b = b
+ (>>) = (*>)
instance Alternative Option where
empty = Option Nothing