1

Possible Duplicate:
When is memoization automatic in GHC Haskell?

It looks like Haskell does not memoize all and every function by default - please note, I'm new to Haskell, so I might have that wrong, and I might be very naive about "universal memoization". This question is to understand if/why Haskell can memoize any function at the language level (maybe a silly question), and if not, what are the challenges? Also, are there other FP languages out there that provide "universal memoization" by default?

I'm curious about this because I tried to write such a "universal memoizer" in Python recently, and realized that there are significant challenges: managing the cache intelligently is one. But also, manufacturing keys from function arguments efficiently in all cases can be challenging. In my applications, it looked like handcrafting application-specific cache keys was more efficient, but that's not always easy. That's when I started wondering about Haskell, and whether Haskell had internal tricks to memoize efficiently on any function argument(s).

Just trying to learn about memoization, FP and Haskell.

Community
  • 1
  • 1
Frank
  • 4,341
  • 8
  • 41
  • 57
  • @Blender: In Haskell, functions are always pure, so you don't ever have functions like that. Anything requiring mutable state is handled with monads. – j_random_hacker Dec 29 '12 at 18:21
  • Haskell implementations don't memoize all function results, as it would waste massive amounts of memory. – Don Stewart Dec 29 '12 at 18:33
  • @DonStewart OK, that's reasonable. Does it detect which function results are needed again and again, and memoize those automatically? – Frank Dec 29 '12 at 18:42
  • 1
    To my knowledge there is no Haskell implementation that does automatic memoization. – augustss Dec 29 '12 at 19:25

0 Answers0