Commit 81b6befa authored by Joachim Breitner's avatar Joachim Breitner
Browse files

go-ify foldr2

This helps with the changes in #7994, but might also generally be a good
idea (ignore the runtime):

--------------------------------------------------------------------------------
        Program           Size    Allocs   Runtime   Elapsed  TotalMem
           fft2          -0.1%     -1.5%      0.07      0.07     +0.0%
       fibheaps          +0.0%    -17.2%      0.03      0.03     +0.0%
          fluid          +0.5%     -0.7%      0.01      0.01     +0.0%
      integrate          +0.0%     -0.9%      0.16      0.16     +0.0%
        rewrite          +0.0%     -1.1%      0.02      0.02     +0.0%
--------------------------------------------------------------------------------
            Min          -0.1%    -17.2%     -1.6%     +0.0%     +0.0%
            Max          +0.5%     +0.0%   +107.7%   +106.2%    +11.3%
 Geometric Mean          +0.0%     -0.2%    +23.7%    +23.9%     +0.1%
parent 9143961e
...@@ -633,11 +633,12 @@ xs !! (I# n0) | isTrue# (n0 <# 0#) = error "Prelude.(!!): negative index\n" ...@@ -633,11 +633,12 @@ xs !! (I# n0) | isTrue# (n0 <# 0#) = error "Prelude.(!!): negative index\n"
\begin{code} \begin{code}
foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c foldr2 :: (a -> b -> c -> c) -> c -> [a] -> [b] -> c
foldr2 _k z [] _ys = z foldr2 k z = go
foldr2 _k z _xs [] = z where
foldr2 k z (x:xs) (y:ys) = k x y (foldr2 k z xs ys) go [] _ys = z
go _xs [] = z
{-# NOINLINE [1] foldr2 #-} go (x:xs) (y:ys) = k x y (go xs ys)
{-# INLINE [0] foldr2 #-}
foldr2_left :: (a -> b -> c -> d) -> d -> a -> ([b] -> c) -> [b] -> d foldr2_left :: (a -> b -> c -> d) -> d -> a -> ([b] -> c) -> [b] -> d
foldr2_left _k z _x _r [] = z foldr2_left _k z _x _r [] = z
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment