I understand if I had the statement c = a AND b, if a was false then the compiler wouldnt bother evaluating b, it would know the result because a is already false.
However, what if I had a function which was recursive and ANDing together the recursive calls.
So myfunc input1 input2 = and[myfunc(input1),myfunc(input2)]
if a function return from any point in the above recursive function-calling tree returned false, would the recursive function calls terminate and the value false would just be evaluated at the original calling point?
In other words, would it use lazy evaluation above?
Yes. In fact, one implementation of
andis recursive (and doesn’t have any strictness added):To show that this works, you can pass an infinite list of
Falses toand, and see that it returnsNote, however, this does not work with an infinite list of
Trues, because it will forever look for aFalse, but never find one.