Stream: beginners

Topic: Confusing roc arithmetic


view this post on Zulip Johannes Rubenz (Nov 09 2025 at 16:25):

I ran into something a bit confusing today:

100 // 10 * 10

gives

1 : Int *

but

100 / 10 * 10

gives

100 : Frac *

I would have expected the first expression to give the same result as the second. Am I missing something here?

view this post on Zulip Matthieu Pizenberg (Nov 09 2025 at 21:26):

Most likely the // operator have a lower priority than / and * which have the same priority I guess.

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:25):

Definitely a bug

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:25):

//, /, and * should all have the same priority.

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:26):

Is this in the rust or the zig version of the compiler?

view this post on Zulip Johannes Rubenz (Nov 09 2025 at 22:29):

I am on roc nightly pre-release, built from commit d73ea109cc2 on Tue Sep 9 10:23:53 UTC 2025.

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:39):

Ok. So that is in then old rust compiler I think.

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:57):

Oh, interesting, in the rust compiler, double slash (integer division) and percent (modulo) are intentionally lower precedence. I still vote that it is a bug though. https://github.com/roc-lang/roc/blob/9243fcdebb0341577201a58e7a5e9c666f4ce2cb/crates/compiler/module/src/called_via.rs#L10-L11

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:57):

Not sure the state in the zig compiler.

view this post on Zulip Brendan Hansknecht (Nov 09 2025 at 22:57):

@Richard Feldman, these should all be the same precedence, right? I think that is what is expected from most languages.


Last updated: Nov 28 2025 at 12:16 UTC