why memoization is not a language feature?

后端 未结 11 614
无人及你
无人及你 2021-01-31 09:00

I was wondering... why memoization is not provided natively as a language feature by any language I know about?

Edit: to clarify, what I mean is that th

11条回答
  •  鱼传尺愫
    2021-01-31 09:08

    Because compilers have to emit semantically correct programs. You can't memoize a function without changing program semantics unless it is referentially transparent. In most programming languages not all functions are referentially transparent (pure functional programming languages are an exception) so you can't memoize everything. But then a mechanism is needed for detecting referential transparency and that is too hard.

提交回复
热议问题