On Saturday 22 May 2010 15:00:25, Thomas Schilling wrote: > Actually, in this case it would be safe to do CSS. Because > > a) the function is strict in both arguments so GHC creates a worker > which only uses unboxed types > b) this cannot cause any space leaks (it contains no pointers) > > The generated Core does look pretty weird, though: > > $wnewton = > \ (ww_s115 :: Double#) (ww1_s119 :: Int#) -> > case ww1_s119 of ds_Xr8 { > __DEFAULT -> > case ^_r11D > (case $wnewton ww_s115 (-# ds_Xr8 1) > of ww2_s11d { __DEFAULT -> > D# ww2_s11d -- box the result of $wnewton > }) > lvl_r11B > of _ { D# x_avk -> -- unbox it again
The boxing is due to the use of (^). If you write x*x instead of x^2, it can use the primop *## and needn't box it. As a side effect, the original time leak probably wouldn't have occured with x*x instead of x^2 because one would've made it let x = newton a (n-1) in (x*x +a) / (2*x) instead of writing out newton a (n-1) thrice anyway, wouldn't one? > case $wnewton ww_s115 (-# ds_Xr8 1) > of ww2_s11d { __DEFAULT -> > /## > (+## x_avk ww_s115) (*## 2.0 ww2_s11d) > } > }; > 0 -> ww_s115 > } > _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe