top | item 41455378

(no title)

Reefersleep | 1 year ago

I don't understand the bit about the execution order, nor how it's relevant in your day-to-day programming.

discuss

order

mbivert|1 year ago

When you execute a function in a mainstream languages, the arguments are usually evaluated first, then the function is called with the result of that evaluation.

E.g. the following in JS will always print the confirm message. But in a lazy language like Haskell, as the x parameter is never used, it'll never be printed.

  (function(x) { return "bar"; })(confirm("foo"));
This can help with implementing things like infinite streams (e.g. iterate[0] in Haskell), which may be a pleasant patterns to solve some problems sometimes. On this example alone, I wouldn't qualify it as highly relevant for day-to-day work, but there may be more interesting use cases I'm not familiar with (I'd guess there might be interesting side-effects in concurrent settings).

[0]: https://hackage.haskell.org/package/base-4.20.0.1/docs/Prelu...