Does Haskell require a garbage collector?

后端 未结 8 1556
北恋
北恋 2020-12-22 15:13

I\'m curious as to why Haskell implementations use a GC.

I can\'t think of a case where GC would be necessary in a pure language. Is it just an optimization to reduc

8条回答
  •  情书的邮戳
    2020-12-22 15:54

    Haskell is a non-strict programming language, but most implementations use call-by-need (laziness) to implement non-strictness. In call-by-need you only evaluate stuff when it is reached during runtime using the machinery of "thunks" (expressions that wait to be evaluated and then overwrite themselves, staying visible for their value to be reused when needed).

    So, if you implement your language lazily using thunks, you have deferred all reasoning about object lifetimes until the last moment, which is runtime. Since you now know nothing about lifetimes, the only thing you can reasonably do is garbage collect...

提交回复
热议问题