[Haskell-cafe] [GHC 7.8.4] IO Monad leak space?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jul 3 09:50:28 UTC 2015


On Fri, Jul 03, 2015 at 08:18:55AM +0000, Baojun Wang wrote:
> Consider below function:
> 
> f3 :: UArray Int Int -> IOUArray Int Int64 -> Int -> IO ()
> f3 u r i = let !v = u ! i
>             in go (f31 v) i i
>   where f31 v j = readArray r j >>= \v1 ->
>           writeArray r j (v1 + (fromIntegral i) * (fromIntegral v))
>         f31 :: Int -> Int -> IO ()
>         go g k s = when (k <= maxn) (
>           g k >> go g (s+k) s )
> 
> When call f3:
> 
>   loopM_ (f3 uu res) 1 1 1000000

Could you provide complete working code (including definitions of uu and
res) and I will have a go at diagnosing.  (My first guess is that you need
to force (v1 + (fromIntegral i) * (fromIntegral v)).)

Tom


More information about the Haskell-Cafe mailing list