Why don't Haskell compilers facilitate deterministic memory management?

前端 未结 5 1576
栀梦
栀梦 2021-02-02 11:48

With the wealth of type information available why can\'t Haskell runtimes avoid running GC to clean up? It should be possible to figure out all usages and insert appropriate cal

5条回答
  •  粉色の甜心
    2021-02-02 12:11

    Consider the following pseudo-code:

    func a = if some_computation a
        then a
        else 0
    

    To know whether a is garbage after calling func a, the compiler has to be able to know the result of some_computation a. If it could do that in the general case (which requires solving the halting problem), thrn there'd be no need to emit code for this function at all, let alone garbage collect it. Type information is not sufficient.

提交回复
热议问题