[Haskell-cafe] Another Space Leak
Anatoly Zaretsky
anatoly.zaretsky at gmail.com
Sun Feb 4 14:16:49 EST 2007
On 2/4/07, Dominic Steinitz <dominic.steinitz at blueyonder.co.uk> wrote:
> test1 :: Int -> [Word8]
> test1 n = foldl' (zipWith xor) [0x01..0x40] (blockWord8sIn512 (pad (replicate
> n 0x55)))
>
> test2 :: Int -> [Word8]
> test2 n = foldl' (zipWith xor) [0x01..0x40] (bws (pad (replicate n 0x55)))
The problem really is here: foldl' demands the value of 'zipWith xor
xs ys' (which is a list) but not its elemants. So we need a modified
zipWith:
zipWith' f xs ys = forceList (zipWith f xs ys)
where forceList zs = foldr seq zs zs
--
Tolik
More information about the Haskell-Cafe
mailing list