Stream: beginners

Topic: Short-circuit on boolean operations


view this post on Zulip JRI98 (Dec 04 2024 at 10:37):

TIL that Roc does not short-circuit on boolean operations. I am surprised I only hit this now :sweat_smile:
For context, the following program is a minimization of what I was trying to do. It crashes because of underflow:

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.17.0/lZFLstMUCUvd5bjnnpYromZJXkQUrdhbva4xdBInicE.tar.br" }

main =
    idx = 0u64
    _ = idx >= 3 && idx - 1 != 0
    Task.ok {}

view this post on Zulip Sam Mohr (Dec 04 2024 at 10:40):

This was just brought up in the operator desugaring discussion. We plan to desugar a && b to if a then b else False and a || b to if a then True else b to implement short circuiting.

view this post on Zulip Sam Mohr (Dec 04 2024 at 10:41):

I don't see an issue for it on GitHub, we should make a few of those once we move towards implementing static dispatch

view this post on Zulip Anthony Bullard (Dec 04 2024 at 13:59):

I'm so glad you hit this before me! How surprising! I don't think I've used a language without short circuiting in a _long_ time

view this post on Zulip Anthony Bullard (Dec 04 2024 at 14:00):

Seems like something you'd want to wait to transform until IR


Last updated: Jul 05 2025 at 12:14 UTC