List patterns

Lists and the values they contain can be pattern matched on in case expressions.

リストとそれに含まれる値は、case 式でパターンマッチさせることができます。

List patterns match on specific lengths of lists. The pattern [] matches an empty list, and the pattern [_] matches a list with one element. They will not match on lists with other lengths.

リストパターンは、特定の長さのリストにマッチします。パターン [] は空のリストにマッチし、パターン [_] は要素が 1 つのリストにマッチします。これらは他の長さのリストにはマッチしません。

The spread pattern .. can be used to match the rest of the list. The pattern [1, ..] matches any list that starts with 1. The pattern [_, _, ..] matches any list that has at least two elements.

スプレッドパターン .. はリストの残りの部分にマッチします。パターン [1, ..]1 から始まるリストにマッチし、パターン [_, _, ..] は少なくとも 2 つの要素を持つリストにマッチします。