[Haskell-cafe] Re: Memoization in Haskell?

2010-07-10 Thread Heinrich Apfelmus
Gregory Crosswhite wrote: Heinrich Apfelmus wrote: Gregory Crosswhite wrote: You're correct in pointing out that f uses memoization inside of itself to cache the intermediate values that it commutes, but those values don't get shared between invocations of f; thus, if you call f with the

[Haskell-cafe] Re: Memoization in Haskell?

2010-07-09 Thread Heinrich Apfelmus
Gregory Crosswhite wrote: You're correct in pointing out that f uses memoization inside of itself to cache the intermediate values that it commutes, but those values don't get shared between invocations of f; thus, if you call f with the same value of n several times then the memo table

Re: [Haskell-cafe] Re: Memoization in Haskell?

2010-07-09 Thread Gregory Crosswhite
That actually doesn't work as long as memo is an array, since then it has fixed size; you have to also make memo an infinitely large data (but lazy) structure so that it can hold results for arbitrary n. One option for doing this of course is to make memo be an infinite list, but a more

[Haskell-cafe] Re: memoization

2009-09-06 Thread John Lato
Hello, I agree that your answer is elegant, but it's not an efficient algorithm in any language. How about this, keeping the rest of your code the same? import Data.Array.Diff import Data.IArray update :: (Char - [Int]) - DiffArray Int ModP - Char - DiffArray Int ModP update lookup arr c = arr

[Haskell-cafe] Re: memoization

2009-09-06 Thread John Lato
I just discovered that changing DiffArray to a plain Array improves performance of my code by almost a factor of 10. Bitten by DiffArray yet again! John -- this is no good, just change DiffArray to Array. update :: (Char - [Int]) - DiffArray Int ModP - Char - DiffArray Int ModP update lookup

Re: [Haskell-cafe] Re: memoization

2009-09-06 Thread Daniel Fischer
Am Sonntag 06 September 2009 13:36:57 schrieb John Lato: I just discovered that changing DiffArray to a plain Array improves performance of my code by almost a factor of 10. Bitten by DiffArray yet again! That's strange. Compiled without optimisations, using plain Array instead of DiffArray

Re: [Haskell-cafe] Re: memoization

2009-09-06 Thread John Lato
On Sun, Sep 6, 2009 at 4:30 PM, Daniel Fischerdaniel.is.fisc...@web.de wrote: Am Sonntag 06 September 2009 13:36:57 schrieb John Lato: I just discovered that changing DiffArray to a plain Array improves performance of my code by almost a factor of 10.  Bitten by DiffArray yet again! That's

Re: [Haskell-cafe] Re: Memoization

2007-06-08 Thread Peter Berry
Sorry for digging up such an old thread, but my undergraduate dissertation is on this topic so I couldn't resist. :) (Some credit in the following goes to my supervisor, Ulrich Berger.) Mark Engelberg wrote: I'd like to write a memoization utility. Ideally, it would look something like

Re: [Haskell-cafe] Re: Memoization

2007-06-08 Thread Peter Berry
On 08/06/07, Peter Berry [EMAIL PROTECTED] wrote: You could generate F and the Memoizable instance using TH or DrIFT or the like (allowing derivation would be really nice :). Actually F could be considered a dependent type, so you could define a pretty much universal instance using TH with that

[Haskell-cafe] Re: Memoization

2007-05-30 Thread Simon Marlow
Rodrigo Queiro wrote: sorear pointed me to this paper a while ago: http://citeseer.ist.psu.edu/peytonjones99stretching.html I never tried any of the code in the end, but it will probably be useful? An implementation of that memo table scheme can be found here:

[Haskell-cafe] Re: Memoization

2007-05-27 Thread apfelmus
Mark Engelberg wrote: I'd like to write a memoization utility. Ideally, it would look something like this: memoize :: (a-b) - (a-b) memoize f gives you back a function that maintains a cache of previously computed values, so that subsequent calls with the same input will be faster.

Re: [Haskell-cafe] Re: Memoization

2007-05-27 Thread Andrew Coppin
apfelmus wrote: Note that due to parametricity, any function of this type is necessarily either id or _|_. In other words, there are only two functions of type ∀a∀b. (a-b) - (a-b) You managed to type ∀ but you couldn't find ⊥ ? OOC, can anybody tell me what ∀ actually means anyway?

Re: [Haskell-cafe] Re: Memoization

2007-05-27 Thread Tony Morris
You managed to type ∀ but you couldn't find ⊥ ? OOC, can anybody tell me what ∀ actually means anyway? It is called the 'universal quantifier' and means for all. It is often used implicitly in natural language. e.g. cars are red can be expanded to [for all elements of the set of cars] cars

Re: [Haskell-cafe] Re: Memoization

2007-05-27 Thread Andrew Coppin
Tony Morris wrote: You managed to type ∀ but you couldn't find ⊥ ? OOC, can anybody tell me what ∀ actually means anyway? It is called the 'universal quantifier' and means for all. It is often used implicitly in natural language. e.g. cars are red can be expanded to [for all elements of

[Haskell-cafe] Re: Memoization

2007-05-27 Thread apfelmus
Andrew Coppin wrote: OOC, can anybody tell me what ∀ actually means anyway? http://en.wikipedia.org/wiki/Universal_quantification http://en.wikipedia.org/wiki/System_F I do recall that GHC has some weird extension called existential quantification

Re: [Haskell-cafe] Re: Memoization

2007-05-27 Thread Isaac Dupree
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 apfelmus wrote: Mark Engelberg wrote: I'd like to write a memoization utility. Ideally, it would look something like this: memoize :: (a-b) - (a-b) memoize f gives you back a function that maintains a cache of previously computed values, so