Stretching the Storage Manager a little too much...
Simon Marlow
simonmarhaskell at gmail.com
Tue Jan 30 04:07:25 EST 2007
Michael Weber wrote:
> [I am reading ghc-bugs via the list archives, Cc'ing me would make me
> see responses faster]
>
> Here's a simple memoization function:
>
> applyMemo :: (Eq a1,Show a1) => (a1 -> b) -> MVar [(a1,b)] -> (a1 -> b)
> applyMemo f refTable x1 = unsafePerformIO $ do
> -- print x1
> table <- takeMVar refTable
> let key = x1
> case lookup key table of
> Nothing -> do
> let result = f x1
> putMVar refTable $! (key,result):table
> return result
> Just memo -> putMVar refTable table >> return memo
>
>
> The code above is a cut-down example. Initially, I tried to use
> Data.HashTable, then IORef (Data.Map ...), then MVars. However, what
> remains is that I get funny results: <<loop>>, "thread blocked
> indefinitely", hangs, depending on the exact implementation of
> applyMemo, whether I use ghci or ghc, and which function I memoize
> (something with a more interesting call pattern than fib).
Would you mind submitting a complete test case that we can use to reproduce the
problem? We can probably reconstruct one from your description, but you
probably already have the code lying around.
Cheers,
Simon
More information about the Glasgow-haskell-bugs
mailing list