Hacker News new | past | comments | ask | show | jobs | submit login

I've use something very similar in practice. Haskell's fixed point operator is:

  fix f = let x = f x in x
This allows you to turn a non-recursive function into a recursive one, it factors the recursion out. It turns out that you can write a similar combinator (usually called mfix or memofix as I recall) that will result in a memoized version of the same recursive function.

So it allows you to abstract away the memoization, write it once and then use it on any recursive function. That way you can write quite natural recursive functions and just memoize them in one wrapper call.

https://hackage.haskell.org/package/memoize-0.8.1/docs/Data-... looks similar to what I ended up with

I used this in competitive programming for a while, it was nice for certain types of dynamic programming problems where the interesting part is the recursive definition, so once I found that there wasn't any more to write. Quite satisfying when it applied.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: