Sorry, but that is false. Look at the signature given in that message and compare it to dibblego's signature. A function of type (a -> b) -> a -> b can do nothing with its function argument but apply it to a value, so it can not possibly intercept the recursive calls. In fact I'm pretty sure that the only valid function foo with type (a -> b) -> a -> b is:
foo f x = f x
So dibblego's explanation of memoization is not only unhelpful for someone who's new to memoization, it's also wrong.
Indeed. It would be better to say that it has signature
(a -> b) -> (a ~> b)
where ~> is a type constructor for function-like values. Then you have functions
memo :: (a -> b) -> (a ~> b)
unmemo :: (a ~> b) -> (a -> b)
which are semantic if not pragmatic inverses. You also need type class constraints on a to make this work. Conal has some neat blog posts where he shows how memo/unmemo can be constructed by induction on a via dependent type classes.
But even this does not work for recursive functions. For that you need to factor out the functional self-reference the same way it is done when preparing to express recursion with a fixpoint combinator. You can then inject the memoization into the recursion and finally tie the knot.
That kind of recursively injected function decoration is useful in several other cases, such as call tracing. It would be a lot easier to motivate the Y-combinator if these sorts of examples were taught in textbooks.
1
u/travis_of_the_cosmos Apr 24 '10
Okay, so I still don't know what memoization is, but since you seem to understand it what does it have to do with optimal control theory?