Re: [Haskell-cafe] Haskell and memoization

2009-12-17 Thread Ozgur Akgun
Maybe not related, but does the following prove next is called once and only once. import qualified Data.ByteString as BS import qualified Data.ByteString.Char8 as BSC next = do nextcache - BS.readFile next.cache let nextint = readInt (BSC.unpack nextcache)

Re: [Haskell-cafe] Haskell and memoization

2009-12-17 Thread Ozgur Akgun
Sorry for the last mail, I now tried it and it returns the next value every time I call it. I was using an unsafeperformIO trick somewhere, and that fas the one resulting in the previously described behaviour. You can just ignore the previous mail. 2009/12/17 Ozgur Akgun ozgurak...@gmail.com

Re: [Haskell-cafe] Haskell and memoization

2009-12-16 Thread michael rice
Subject: Re: [Haskell-cafe] Haskell and memoization To: Daniel Fischer daniel.is.fisc...@web.de, Gregory Crosswhite gcr...@phys.washington.edu Cc: haskell-cafe@haskell.org Date: Wednesday, December 16, 2009, 12:58 AM Hi all, I think this (#3 below) is where I got the idea: http://en.wikipedia.org

Re: [Haskell-cafe] Haskell and memoization

2009-12-16 Thread Daniel Fischer
Am Mittwoch 16 Dezember 2009 15:49:54 schrieb michael rice: Thanks all, OK, so this definition of fib fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2) would involve a lot of recomputation for some large n, Where large can start as low as 20; 60 would be out of reach. which memoization

[Haskell-cafe] Haskell and memoization

2009-12-15 Thread michael rice
___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Daniel Peebles
/Memoization Since (I've read) Haskell never computes the value of a function more than once, I don't understand the need for memoization. Enlighten me. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Gregory Crosswhite
://www.haskell.org/haskellwiki/Memoization Since (I've read) Haskell never computes the value of a function more than once, I don't understand the need for memoization. Enlighten me. Michael ___ Haskell-Cafe mailing list Haskell-Cafe

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Daniel Fischer
Am Mittwoch 16 Dezember 2009 05:08:39 schrieb Gregory Crosswhite: Haskell does not maintain a cache mapping function calls to their values, so if you have some function f and call it with, say, the argument 7 in two different places in your code, then it will re-evaluate the function at each

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Gregory Crosswhite
Hmm, you raise an On Dec 15, 2009, at 8:28 PM, Daniel Fischer wrote: Am Mittwoch 16 Dezember 2009 05:08:39 schrieb Gregory Crosswhite: Not even then, necessarily. And it's not always a good idea. f k = [1 .. 20^k] You raise a really good point here. One can force sharing, as I

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread michael rice
return q, as occurs in memoization. Michael --- On Tue, 12/15/09, Gregory Crosswhite gcr...@phys.washington.edu wrote: From: Gregory Crosswhite gcr...@phys.washington.edu Subject: Re: [Haskell-cafe] Haskell and memoization To: Daniel Fischer daniel.is.fisc...@web.de Cc: haskell-cafe@haskell.org

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Daniel Fischer
Am Mittwoch 16 Dezember 2009 05:47:20 schrieb Gregory Crosswhite: On Dec 15, 2009, at 8:28 PM, Daniel Fischer wrote: Am Mittwoch 16 Dezember 2009 05:08:39 schrieb Gregory Crosswhite: Not even then, necessarily. And it's not always a good idea. f k = [1 .. 20^k] You raise a really good

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Gregory Crosswhite
...@phys.washington.edu wrote: From: Gregory Crosswhite gcr...@phys.washington.edu Subject: Re: [Haskell-cafe] Haskell and memoization To: Daniel Fischer daniel.is.fisc...@web.de Cc: haskell-cafe@haskell.org Date: Tuesday, December 15, 2009, 11:47 PM Hmm, you raise an On Dec 15, 2009, at 8:28 PM, Daniel

Re: [Haskell-cafe] Haskell and memoization

2009-12-15 Thread Daniel Fischer
Am Mittwoch 16 Dezember 2009 07:22:42 schrieb Gregory Crosswhite: #3 is true for Haskell, it's just that when your function call appears in two different places, it is counted as two different expressions. Each separate expression will only be evaluated once, though. This is what is really