[GHC] #14224: zipWith does not inline

GHC ghc-devs at haskell.org
Tue Sep 12 22:26:30 UTC 2017


#14224: zipWith does not inline
-------------------------------------+-------------------------------------
           Reporter:  dfeuer         |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.4.1
          Component:  Core           |           Version:  8.2.1
  Libraries                          |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Runtime
  Unknown/Multiple                   |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 `zipWith` is currently defined

 {{{#!hs
 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
 }}}

 For now (I gather that might change soon?), the fact that it's recursive
 means that it will never inline. But we really want it to inline when
 applied to a function, for the same reasons we want `map` to inline. If
 `f` is something like `const`, `flip const`, or a lazy constructor, it's
 wasteful to create a thunk to apply it. All three of those cases are
 common. So unless/until we start inlining recursive functions, we probably
 want to use

 {{{#!hs
 zipWith f = go where
   go [] _ = []
   go _ [] = []
   go (x:xs) (y:ys) = f x y : go xs ys
 }}}

 There will probably be some regressions, of course.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14224>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list