Hi Bulat,
Bulat Ziganshin-2 wrote: > > Hello staafmeister, > > Thursday, September 10, 2009, 3:54:34 PM, you wrote: > >> What do you think about such a function? This function is > > a bit of refactoring > > -- "global variable" in haskell way > cache = unsafePerformIO $ newIORef M.empty > > memo f x = unsafePerformIO$ do > m <- readIORef cache > case M.lookup x m of > Just y -> return y > Nothing -> do let res = f x > writeIORef cache $ M.insert x res m > return res > > memo2 = curry . memo . uncurry > This doesn't work and is exactly what I'm afraid the compiler is going to do. Cache needs to be associated with the function f. Otherwise one would get conflicts Greetings -- View this message in context: http://www.nabble.com/memoization-tp25306687p25382341.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe