Thunk Value - anssihalmeaho/funl GitHub Wiki

Thunk value stores expression and related scope (expression is to be evaluated in it's original scope). Expression is not evaluated until explicitly required (by force operator). Evaluation result (value) is stored to thunk so that consequent inquiries for its value only read already evaluated value.

Thunk is promise to compute something (only) when forced to do that. Thunk can be used in pure functions (as well as in impure procedures). Thunk is thread-safe.

Operators for thunk:

  • defer: creates thunk value for given expression
  • force: forces evaluation of thunk value