First let me say that Roc might be the nicest functional languages Ive come across.
One thing that always irks me though is how if statements seem like they are always ripped right from the imperative world — clunky keywords with blocked statements.
How to fix? On the face of it, if is a function that takes three arguments— a boolean and two lambdas. So we might write something like:
ifElse (foo) (\{} -> doThus) (\{} -> doElse)
Forgive me if this isn’t quite the right syntax. I am new to Roc, but I think the idea is clear.
However, this isn’t the nicest looking b/c of parens and empty args. Some sugar would be nice.
It occurs to me that it should be possible to unify if and when into a single construct.
foo if
Bool.true -> doThus
Bool.false -> doElse
With a special character for Bool.true, say | (pick whatever you prefer) then
foo if
| -> doThus
_ -> doElse
when would be the same just different pattern matches.
bar if
Ok v -> …
Err e -> …
Seems very elegant to me. Thoughts?
Many variations of this topic have been discussed in extreme depth before and it was decided to stay with the current syntax :)
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/.E2.9C.94.201.20line.20pattern.20match.20.2B.20.60when.20is.60-like.20bool.20structure
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/single.20line.20pattern.20matching
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/kotlin-like.20decision.20structures
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/eliminate.20.60then.60.20keyword
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/harmonize.20decision.20structures
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/.E2.9C.94.20adjust.20meaning.20of.20else
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/Prevent.20.60else.20if.60
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/elif.20syntax
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/cond-like.20if.20syntax
Last updated: Jun 16 2026 at 16:19 UTC