[Haskell-cafe] Why are && and || right-associative?

Ryan Reich ryan.reich at gmail.com
Sat Apr 13 03:21:34 UTC 2019


> I don't understand how laziness enters the picture:
>
>     (False && ⊥) && ⊥ ≡ False
>     False && (⊥ && ⊥) ≡ False
>
> in both cases we get the same result.
>

The first expression builds two thunks before trying the leftmost operand,
and the second one only builds one thunk.  More generally, a
left-associative conjunction of n lazy Bools will build n - 1 thunks at
once when forced, but a right-associative one will have only one at a time,
though it may have to iterate through all n - 1 before finishing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20190412/3df6333d/attachment.html>


More information about the Haskell-Cafe mailing list