sumArray MArray Num Ix sumArray do bounds getBounds foldM readArray re

1
2
3
4
sumArray :: (MArray a e m, Num e, Ix i) => a i e -> m e
sumArray a = do
bounds <- getBounds a
foldM (\s i -> readArray a i >>= return . (+s)) 0 (range bounds)