oop - 延迟加载 vs thunking?

标签 oop functional-programming lazy-loading lazy-evaluation

最近我听到了它们的定义,对我来说它们听起来是相同的。 thunk 与延迟加载相同吗?如果不是,这两个定义有什么区别?

最佳答案

使用以下定义:

延迟加载

Lazy loading is a design pattern commonly used in computer programming to defer initialization of an object until the point at which it is needed.

重击

A thunk is an unevaluated expression, often represented as an object on the heap with bound variables and a code pointer (a closure). Lazy evaluation replaces thunks by more evaluated forms (pure values for simple types but otherwise an evaluated outer structure, and possibly unevaluated inner contents, i.e., weak head normal form). That replacement is done destructively, i.e., a side-effect of evaluation.

您可能会说“延迟加载”是一种在面向对象语言中将计算推迟到第一次需要对象时的方法。当需要该值时,将评估整个对象。

thunk 的相似之处在于它是推迟对函数式编程语言中任何表达式求值的方法。当需要时,重击将被替换为其评估的内容,这可能是另一个重击。在像 Haskell 这样的语言中,所有值(理论上)都由 thunk 表示,使得每个评估步骤都可能是惰性的。

它们是大致相似的机制,用于实现相同的最终目标:非严格评估。

关于oop - 延迟加载 vs thunking?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26828898/

相关文章:

linux - linux 中的透明惰性 makefile

Haskell:了解与 lambda 函数一起使用时的映射函数

scala - Ref/MVar 的有效更新

.net - .NET 3.5 中的 EnumerateFiles() 等效项

c++ - 对基类和派生类使用静态容器

scala - 将 F-Algebra[F, A] 组合成 F-Algebra[F, Seq[A]]

cocoa - 实现类似 Finder 的 TreeView ,并使用 NSOutlineview 延迟加载来表示其节点

Javascript OOP - 声明对象的方法

c++ - 为什么嵌套函数的想法没有在旧的 C++ 标准中实现?

oop - 如何在 MATLAB 中预分配类数组?