[Haskell-cafe] function result caching

Silviu Gheorghe ghesil.lists at gmail.com
Sat Oct 14 16:11:18 EDT 2006


thank you for all the answers
i was aware lists are is not the best solution, but i was too keen to see
the actual result

I'll do some tests though using different variants, because i have the
feeling that in my next program I'll face the "strong" form of this problem.

On 10/13/06, Silviu Gheorghe <ghesil.lists at gmail.com> wrote:
>
> it does, thank you very much for the quick answer, unfortunately as I
> understand it, it doesn't work well on ints :(
>
> for just now i created a list
>
> slowFunctionCacheList= [slowFunction (i) | i <-[0..5000000]]
> and use "slowFunctionCacheList !! i" instead of "slowFunction (i)"
>
> it helped alot (i mean i stoped the program after "3 hours still working"
> and got the result in 2 minutes :))
>
> i am still curious about a better method (and a general one), because this
> is ugly, and it only works on ints as i see it.
>
> but then again thank you for telling me it doesn't do it, because i had
> the false impresion it does and i wouldn't stop it otherwise
>
> On 10/13/06, Tom Phoenix <rootbeer at redcat.com> wrote:
> >
> > On 10/12/06, Silviu Gheorghe <ghesil.lists at gmail.com> wrote:
> >
> > > I'd like to know if the results are "cached"  by the compiler
> >
> > Hardly ever, as I understand things.
> >
> > > if they are not I'd like to know what is the best way to cache them
> > > manually, and where can I read more about this, and the optimizations
> > the
> > > compiler does, because I've searched the web before and i found very
> > little
> > > on this topic.
> >
> > You need to search for the word "memoize" (or "memoise"). Here's a
> > page about a memo function for GHC.
> >
> >      http://www.haskell.org/ghc/docs/6.4.2/html/hslibs/memo-library.html
> >
> > Hope this helps!
> >
> > --Tom Phoenix
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061014/b8c36774/attachment.htm


More information about the Haskell-Cafe mailing list