diff options
author | HE, Tao <sighingnow@gmail.com> | 2017-09-19 16:58:19 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-09-19 16:58:21 -0400 |
commit | 11d9615e9f751d6ed084f1cb20c24ad6b408230e (patch) | |
tree | 887115096b011ff91dfb1fab81c7d03ff32417f7 | |
parent | 0aba999f60babe6878a1fd2cc8410139358cad16 (diff) | |
download | haskell-11d9615e9f751d6ed084f1cb20c24ad6b408230e.tar.gz |
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
-rw-r--r-- | libraries/base/GHC/List.hs | 15 | ||||
-rw-r--r-- | 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 37bba9ac3e..af502134a7 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 f64129965f..5fd7ba3665 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* |