4 ms·
And in Haskell, foldl (+) 1 (map face_value dice) would use fusion to avoid causing map to create another array!
by lsb 16y ago
And in Haskell,
foldl (+) 1 (map face_value dice)
would use fusion to avoid causing map to create another array!
- nominolo 16y agoIncidentally fusion won't work for this example (at least not as currently implemented.) Only `foldr` is fusable. Fortunately, regular inlining does just fine. There is of course an even simpler version: sum (map face_value dice)
- ramchip 16y agoWhy does the sum start with 1? Why not eg. foldl1' (+) $ map face_value dice
- loup-vaillant 16y agoIt should have started with 0. Sorry. And I avoided `foldl1` because I wanted to stay close to C++'s `accumulate`.