On Sat, 22 Sep 2007, Peter Verswyvelen wrote:

Hi,

in SOE, the following memoization function is implemented:

memo1 :: (a->b) -> (a->b)
memo1 f = unsafePerformIO $ do
cache <- newIORef []
return $ \x -> unsafePerformIO $ do
            vals <- readIORef cache
            case x `inCache` vals of
              Nothing -> do let y = f x
writeIORef cache [(x,y)] -- ((x,y) : -- if null vals then [] else [head vals])
                            return y
              Just y  -> do return y

Hm, why the unsafePerformIO hacks? It should be possible without:
  http://www.haskell.org/haskellwiki/Memoization
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to