> From: "Brian Goetz" <brian.go...@oracle.com>
> To: "Remi Forax" <fo...@univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts@openjdk.java.net>
> Sent: Thursday, May 19, 2022 3:03:55 PM
> Subject: Re: Collections patterns

>> We may want to extract sub-parts of the array / collections by example, and i
>> would prefer to have the same semantics and a similar syntax.

> This is pretty vague, so I'll have to guess about what you might mean.

> Maybe you mean: "I want to match a list if it contains the a subsequence that
> matches this sequence of patterns", something like:

> [ ... p1, p2, ... ]

> There is surely room to have APIs that query lists like this, but I think this
> is way out of scope for a pattern matching feature the language. Pattern
> matching is about _destructuring_. (Destructuring can be conditional.) An 
> array
> is a linear sequence of elments; it can be destructured by a linear sequence 
> of
> patterns.

> Maybe you mean: "I want to decompose a list into the head element and a tail
> list".

> In Haskell, we iterate a list by recursion:

> len :: [a] -> Int
> len [] = 0
> len x:xs = 1 + len xs

> But again, this is *mere destructuring*, because the cons operator (:) is the
> linguistic primitive for aggregation, and [ ... ] lists are just sugar over
> cons. So matching to `x:xs` is again destructuring. We could try to apply this
> to Java, but it gets very clunky (inefficient, no tail recursion, yada yada)
> because our lists are *built differently*. Further further, arrays are another
> step removed from lists even.

> Or maybe you mean something else; if so, please share!
The current proposal is more about matching and extracting the first arguments 
than matching/extracting the last arguments or the rest are also useful IMO. 
By example, if i want to parse command line arguments composed of options and a 
filename, i may want to write something like 

case [String... options, String filename] -> ... 
case [String...] -> help() 

RĂ©mi 

Reply via email to