This works:
b = |lst| {
match lst {
[h, ..] if h < 4 => "a"
_ => ""
}
}
expect [3] |> b |> Str.is_eq("a")
expect [] |> b |> Str.is_eq("")
But if I want to have tail as an variable it does not work:
Error: I was parsing a pattern, and this token cannot start a pattern here. [h, .. as _t] if h < 4 => "a"
b = |lst| {
match lst {
[h, .. as _tail] if h < 4 => "a"
_ => ""
}
}
expect [3] |> b |> Str.is_eq("a")
expect [] |> b |> Str.is_eq("")
this should work right, or is there any other way to have an if with head and tail as variable?
oh it's just that the syntax is [h, ..tail]
no as needed, although I do think that's an obvious thing to reach for, and we should give a nicer error message for that - would you mind opening a github issue for that @removewingman?
Im confused, when was the change I am on: nightly-2026-09-02-d2609e2
And got this error message:
✗ old list rest pattern ─────────────────────────────────────────────────────────────────────────── /tmp/xdd.roc:4:13
I was parsing a list pattern, and this uses the old rest syntax.
[h, ..tail] if h < 4 => "a"
^^^^^^
List rest patterns now use .. as name. The name is optional, but if it is present it must come after as.
For example:
[first, .. as rest]
(Will upgrade to latest and try again)
That as syntax is supported on latest nightly and latest main branch:
https://github.com/roc-lang/roc/blob/main/test/echo/all_syntax_test.roc
oh it used to be ..tail - maybe we changed it for the new compiler :sweat_smile:
This example does not work tho:
b = |lst| {
match lst {
[h, .. as _tail] if h < 4 => "a"
_ => ""
}
}
expect [3] |> b |> Str.is_eq("a")
expect [] |> b |> Str.is_eq("")
It is probably a bug right? Opened this issue: https://github.com/roc-lang/roc/issues/11109
I actually like, the ..tail syntax a little bit more.
removewingman has marked this topic as resolved.
See https://github.com/roc-lang/roc/issues/7091
Last updated: Sep 24 2026 at 15:59 UTC