4 ms·
> If JavaScript was lazy, it would not evaluate 2+3 in the expression ifThen(1 === 0, 2 + 3) It depends. Haskell is lazy, but I think it would still constant f
by fao_ 11y ago
> If JavaScript was lazy, it would not evaluate 2+3 in the expression ifThen(1 === 0, 2 + 3)
It depends. Haskell is lazy, but I think it would still constant fold that expression.
- chrisseaton 11y agoIf Haskell were lazy, then it wouldn't evaluate 2+3, but Haskell is non-strict, rather than lazy, so it can evaluate it, or not.
- hvidgaard 11y agoHaskell is lazy, but the compiler can be smart enough to know that 2+3 is semantically equal to 5 in it's model of computation. This is without violating the lazy nature of the language. So it can (and will I believe, but I haven't checked) fold any such expressions to their constant value when compiling for performance reasons.
- braythwayt 11y agoJavaScript compilers _ought_ to do that too. The example of generating a billion numbers is more relevant, but I didn’t want to use that until I was ready to introduce a lazy version of it.