diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2015-10-12 11:36:01 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2015-10-12 11:36:12 +0200 |
commit | e737a5126dcfdd0610587d2ec16bea6481cf2a42 (patch) | |
tree | 03b5a0730980021ea72741bc63818e90b10090d0 /libraries/base/Text | |
parent | 4bd58c179b8d0f8cf2850acb920cef8605826a2a (diff) | |
download | haskell-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/Text')
-rw-r--r-- | libraries/base/Text/ParserCombinators/ReadP.hs | 7 | ||||
-rw-r--r-- | libraries/base/Text/ParserCombinators/ReadPrec.hs | 3 |
2 files changed, 3 insertions, 7 deletions
diff --git a/libraries/base/Text/ParserCombinators/ReadP.hs b/libraries/base/Text/ParserCombinators/ReadP.hs index 034411d6bf..bae2abc90e 100644 --- a/libraries/base/Text/ParserCombinators/ReadP.hs +++ b/libraries/base/Text/ParserCombinators/ReadP.hs @@ -103,7 +103,7 @@ data P a -- Monad, MonadPlus instance Applicative P where - pure = return + pure x = Result x Fail (<*>) = ap instance MonadPlus P where @@ -111,8 +111,6 @@ instance MonadPlus P where mplus = (<|>) instance Monad P where - return x = Result x Fail - (Get f) >>= k = Get (\c -> f c >>= k) (Look f) >>= k = Look (\s -> f s >>= k) Fail >>= _ = Fail @@ -161,11 +159,10 @@ instance Functor ReadP where fmap h (R f) = R (\k -> f (k . h)) instance Applicative ReadP where - pure = return + pure x = R (\k -> k x) (<*>) = ap instance Monad ReadP where - return x = R (\k -> k x) fail _ = R (\_ -> Fail) R m >>= f = R (\k -> m (\a -> let R m' = f a in m' k)) diff --git a/libraries/base/Text/ParserCombinators/ReadPrec.hs b/libraries/base/Text/ParserCombinators/ReadPrec.hs index 027648d9e8..02268364ca 100644 --- a/libraries/base/Text/ParserCombinators/ReadPrec.hs +++ b/libraries/base/Text/ParserCombinators/ReadPrec.hs @@ -75,11 +75,10 @@ instance Functor ReadPrec where fmap h (P f) = P (\n -> fmap h (f n)) instance Applicative ReadPrec where - pure = return + pure x = P (\_ -> pure x) (<*>) = ap instance Monad ReadPrec where - return x = P (\_ -> return x) fail s = P (\_ -> fail s) P f >>= k = P (\n -> do a <- f n; let P f' = k a in f' n) |