[commit: ghc] master: Make zipWith and zipWith3 inlinable. (11d9615)
git at git.haskell.org
git at git.haskell.org
Tue Sep 19 22:54:48 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/11d9615e9f751d6ed084f1cb20c24ad6b408230e/ghc
>---------------------------------------------------------------
commit 11d9615e9f751d6ed084f1cb20c24ad6b408230e
Author: HE, Tao <sighingnow at gmail.com>
Date: Tue Sep 19 16:58:19 2017 -0400
Make zipWith and zipWith3 inlinable.
Reviewers: austin, hvr, bgamari, dfeuer
Reviewed By: dfeuer
Subscribers: rwbarton, thomie
GHC Trac Issues: #14224
Differential Revision: https://phabricator.haskell.org/D3986
>---------------------------------------------------------------
11d9615e9f751d6ed084f1cb20c24ad6b408230e
libraries/base/GHC/List.hs | 15 +++++++++------
libraries/base/changelog.md | 2 ++
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/libraries/base/GHC/List.hs b/libraries/base/GHC/List.hs
index 37bba9a..af50213 100644
--- a/libraries/base/GHC/List.hs
+++ b/libraries/base/GHC/List.hs
@@ -992,9 +992,11 @@ zip3 _ _ _ = []
-- > zipWith f [] _|_ = []
{-# NOINLINE [1] zipWith #-}
zipWith :: (a->b->c) -> [a]->[b]->[c]
-zipWith _f [] _bs = []
-zipWith _f _as [] = []
-zipWith f (a:as) (b:bs) = f a b : zipWith f as bs
+zipWith f = go
+ where
+ go [] _ = []
+ go _ [] = []
+ go (x:xs) (y:ys) = f x y : go xs ys
-- zipWithFB must have arity 2 since it gets two arguments in the "zipWith"
-- rule; it might not get inlined otherwise
@@ -1011,9 +1013,10 @@ zipWithFB c f = \x y r -> (x `f` y) `c` r
-- elements, as well as three lists and returns a list of their point-wise
-- combination, analogous to 'zipWith'.
zipWith3 :: (a->b->c->d) -> [a]->[b]->[c]->[d]
-zipWith3 z (a:as) (b:bs) (c:cs)
- = z a b c : zipWith3 z as bs cs
-zipWith3 _ _ _ _ = []
+zipWith3 z = go
+ where
+ go (a:as) (b:bs) (c:cs) = z a b c : go as bs cs
+ go _ _ _ = []
-- | 'unzip' transforms a list of pairs into a list of first components
-- and a list of second components.
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index f641299..5fd7ba3 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -45,6 +45,8 @@
* Add missing `MonadFail` instance for `Control.Monad.Strict.ST.ST`
+ * Make `zipWith` and `zipWith3` inlinable (#14224)
+
## 4.10.0.0 *April 2017*
* Bundled with GHC *TBA*
More information about the ghc-commits
mailing list