what is the difference between thunk, futures, and promises?

An example of each, using javascript since everybody can read it. Please don’t use this code in production, use a real library, there are plenty of good ones. var a, b, c, async_obj; // assume exist // CommonJS – for reference purposes try { async_obj.asyncMethod(a, b, c, function (error1, result1) { if (error1) { console.error(error1); … Read more

Understanding the different behavior of thunks when GHCi let bindings are involved

Because (,) is a constructor, the difference makes no difference to Haskell’s semantics (:sprint gives access to internal thunk implementation details so doesn’t count.) So this is a question of which optimizations and trade-offs GHC does when compiling (x,x) in different positions. Someone else may know the precise reason in these cases.

Is everything in Haskell stored in thunks, even simple values?

Official answer It’s none of your business. Strictly implementation detail of your compiler. Short answer Yes. Longer answer To the Haskell program itself, the answer is always yes, but the compiler can and will do things differently if it finds out that it can get away with it, for performance reasons. For example, for ”’add … Read more

What is a ‘thunk’?

A thunk usually refers to a small piece of code that is called as a function, does some small thing, and then JUMPs to another location (usually a function) instead of returning to its caller. Assuming the JUMP target is a normal function, when it returns, it will return to the thunk’s caller. Thunks can … Read more