<div dir="ltr">The following higher order function, sumh, seems to be 3 to 14 times slower than the equivalent recursive function, sumr:<div><br></div><div><div>sumh :: Double -> Double                     </div><div>sumh n =</div><div>    snd $ until ((>= n) . fst) as' (1, 0)</div><div>    where</div><div>      as' (i,s) =</div><div>          (i + 2, s + (-1) / i + 1 / (i + 1))</div></div><div><br></div><div><div>sumr :: Double -> Double</div><div>sumr n =</div><div>    as' 1 0</div><div>    where</div><div>      as' i  s</div><div>          | i >= n    = s</div><div>          | otherwise = as' (i + 2) (s + (-1) / i + 1 / (i + 1))</div></div><div><br></div><div>This is true in 7.10.3 as well as 8.0.1 so this is not a regression. From the size usage my guess is that this is due to the allocation of tuples in sumh. Maybe there is a straightforward way to optimize sumh but I couldn't find it. Adding a Strict pragma didn't help nor did use of -funbox-strict-fields -flate-dmd-anal. Have I missed something or should I file a bug? </div><div><br></div><div>Timings from 8.0.1 rc2:</div><div><br></div><div><div>ghc --version</div><div>The Glorious Glasgow Haskell Compilation System, version 8.0.0.20160204</div><div>bash-3.2$ ghc -O2 -dynamic sum.hs</div><div>ghc -O2 -dynamic sum.hs</div><div>[1 of 1] Compiling Main             ( sum.hs, sum.o )</div><div>Linking sum ...</div><div>bash-3.2$ ghci</div><div>Prelude> :load sum</div><div>Ok, modules loaded: Main.</div><div>(0.05 secs,)</div><div><div>Prelude Main> <b>sumh</b> (10^6)</div><div>-0.6931466805602525</div><div>it :: Double</div><div>(<b>0.14 secs, 40,708,016 bytes</b>)</div></div><div>Prelude Main> sumr (10^6)</div><div>-0.6931466805602525</div><div>it :: Double</div><div>(<b>0.01 secs, 92,000 bytes)</b></div><div><br></div></div><div>Thanks</div><div>George</div></div>