
7 Feb
2008
7 Feb
'08
11:34 a.m.
On Feb 2, 2008 12:11 PM, Chaddaï Fouché
To address this I propose this function : foldl1MArray' :: (MArray a e m, Ix i) => (e -> e -> e) -> a i e -> m e foldl1MArray' f a = do (l,u) <- getBounds a firstElem <- readArray a l foldM (\a mb -> a `seq` mb >>= return . f a) firstElem (map (readArray a) (range (l,u)))
I played with your foldl1MArray' last night. I noticed it can be reduced to . . . foldl1MArray' :: (MArray a e m, Ix i) => (e -> e -> e) -> a i e -> m e foldl1MArray' f a = do (l,u) <- getBounds a foldl1' (liftM2 f) (map (readArray a) (range (l,u))) Unfortunately, my new version consumes a lot of stack and heap space. Why is this so inefficient? Is there a simple change that will make it efficient?