what if instead of having | separate different alternatives in pattern matches, we used or?
e.g.
when result is
Ok(str) -> str
Err(FileErr or BadUtf8) -> "err"
seems more self-descriptive
It is more self-descriptive, but the value of symbols here are that they're more visually sparse and distinct than words. I think the pipe is better at chunking patterns for the eyes
Though or would make parsing simpler/more performant, the parser is probably so cheap compared to the rest of the compiler that I don't think a minor readability loss is worth it
If everyone else thinks it's more readable, then sure. That's separate, though
yeah that's why I didn't bring up the parsing considerations here - I'm curious what others think just in terms of how the code reads!
Really depends on the syntax highlighting
If it’s good, I think it reads fine
let's assume it's good :big_smile:
Though this style you’ve put here is unusual
An or pattern in the interior of another pattern that is
yeah I don't think we actually support it yet :sweat_smile:
I’d expect to see:
when result is
Ok(str) -> str
Err(FileErr) or Err(BadUtf8) -> "err"
Are you including that in this proposal?
Maybe there is a benefit to having a different syntax for "Types" | as opposed to "values" or.
Personally I think the or is objectively clearer and more expressive of intent.
IE, making alternatives inside of a pattern legal?
I think we should absolutely allow that
It's very useful at removing clutter from complex patterns
I don’t know if I’ve seen that in a language
But seems useful
when tag_union is
Apples -> "delicious"
Bananas | Oranges | _ -> "gross"
when tag_union is
Apples -> "delicious"
Bananas or Oranges or _ -> "gross"
Makes me want to suggest:
when tag_union is
Apples then "delicious"
Bananas or Oranges or _ then "gross"
Rust does it
wait we all know that Roc already supports | like this today, right?
I'm just talking about renaming it to or
It supports it inside of a destructure?
I'm talking with Anthony about | within a pattern
Like Rust does
I don’t think I’ve ever seen that in Rust either, but I trust Sam on that
I think it's fine with syntax highlighting
You’d definitely want different formatting I think for multiline
Trailing or instead of leading with |
I still have no good heuristic for when we use symbols instead of keywords. It feels like we do it for
gtewhen tag_union is
Apples -> "delicious"
Bananas or
Oranges or
_ -> "gross"
I really don't like that you need to read the end of a line to scan the code
Not a fan of or if that's required
Wow, really?
Not perfect either, but we can use two spaces before the or to keep it at the start of the line
This reads better to you?
when tag_union is
Apples -> "delicious"
Bananas
or Oranges
or _ -> "gross"
I've been trying to push for scanability
That’s what the trailing or was for
I figured with syntax highlighting it’s distinct
And I think we either need an obvious symbol like | or some indent
when tag_union is
Apples -> "delicious"
Bananas
or Oranges
or _ -> "gross"
I want to really narrowly scope what I'm talking about in this thread
it's just find/replace | with or, that's it :big_smile:
everything else is out of scope for this idea
I agree
Sure
But how we format code with or affects my decision
Then this is what you get on multiline:
when tag_union is
Apples -> "delicious"
Bananas
or Oranges
or _ -> "gross"
And I think that influences opinions
Because as Anthony is pointing out, the readability is worse for multiline
If we couldn't change formatting, I'd say it's not worth it
Even if we could, I'm not sure
Without the real syntax highlighting it might be hard to gauge fairly
In Ruby or is an operator not a keyword
If when, is, and or were highlighted the same it might strike you differently
what does the ideal or formatting look like next to the ideal | formatting?
(I'm on mobile, can't write them out easily :sweat_smile:)
Well I thought this #ideas > `or` instead of `|` in `when` branches @ 💬 for single line
Or this for multi-line
when tag_union is
Apples ->
"delicious"
Bananas
| Oranges
| _ ->
"gross"
when tag_union is
Apples _ _ _ _ _ _ _ ->
"delicious"
Bananas _ _ _ _ _ _ _
or Oranges _ _ _ _ _ _ _
or _ ->
"gross"
edit : updated based on Sam's comment below
I think the newlines are doing work here
If the patterns are longer for the or example, it's a bigger problem that or is at the end
Updated it to have leading or to help with longer patterns
To my eyes, the trailing or still reads better
But I am but one man
Anthony Bullard said:
To my eyes, the trailing or still reads better
Here you go
when tag_union is
Apples _ _ _ _ _ _ _ ->
"delicious"
Bananas _ _ _ _ _ _ _ or
Oranges _ _ _ _ _ _ _ or
_ ->
"gross"
I like the trailing or. I'm definitely more familiar with the |.
I do think the or's are clearer for someone who isn't already steeped in programming language syntax. It almost reads like a sentence.
it feels to me like the tradeoffs between or and | are similar to the tradeoffs between or and || in terms of readability
Luke Boswell said:
I like the trailing
or. I'm definitely more familiar with the|.I do think the
or's are clearer for someone who isn't already steeped in programming language syntax. It almost reads like a sentence.
This is why I have-jokingly suggested that if this moved forward, replacing -> with then makes sense as well. But there are lots of opinions on words over symbols here
I personally like then over -> in the abstract
it wasn't well-received last time but I also don't think we really seriously considered it haha
(the thing I like about it in the abstract is just that -> now means "pure function" and when branches are purity-agnostic)
Yep
I like then also... in general I think the keywords are clearer.
Especially with control flow
if anyone wants to start a thread about it, feel free!
I really dislike or in when branches, just feels verbose and overly wordy....but I am used to rust which just uses a |. I like or for booleans. I'm not a fan of it for patterns.
But I'm sure I would eventually get used to whatever
Yeah I also much prefer pipe here
I like or. I feel like it unifies the syntax with ifs. It seems inconsistent to have different operators when you're "matching" on boolean expressions vs matching on types. It would be nice to be able to read ifs and whens in the same way and that could be another argument for adding then too
I mean they functionally do different things
One is selecting from many possible patterns. The other passing on the first true value found with short circuiting.
Just to push a bit - if can be thought of as matching when you're interested in one possible pattern. when pattern matching can short circuit as well.
There is nothing to short circuit cause there are no evaluated expressions
Brendan Hansknecht said:
There is nothing to short circuit cause there are no evaluated expressions
You're right, I take that back
But yeah, I do agree that they still roughly are the same idea, so it may feel nice for consistency.
when tag_union is
Apples _ _ _ _ _ _ _ -> "delicious"
Bananas _ _ _ _ _ _ _ or
Oranges _ _ _ _ _ _ _ or
_ ->
"gross"
This is what I think will get hairy. We can force the formatter to move single line branches to be multiline if any patterns are multiline? Not great, but I think it'd be better than the above
Or is very familiar in expressions, but seeing it in a pattern match makes me feel like it's doing some sort of calculation or transformation of the types, but it's really more like control flow here. Like, Err(FileErr or BadUtf8) -> makes me think you're creating some new type/value/concept FileErr or BadUtf8, and it makes me want to do something like
pattern myPattern = FileErr or BadUtf8
...
Err(myPattern) ->
By contrast | feels more like it's part of the control flow and the syntax of when, just like , is part of the syntax of lists, and I don't have the same urge to see it as a calculation or pull it into a variable.
seems like there isn't enough interest to justify changing, so let's keep it as |
Sky Rose has marked this topic as resolved.
Last updated: Jun 16 2026 at 16:19 UTC