You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose we add a scope type for the patterns in pattern matches, which are very important in functional languages like Haskell, Scala, and Rust, and increasingly important in languages such as JavaScript (see tc39) and Python (see pep 636).
// TypeScriptfunctionfst<A,B>(tup: [A,B]){const{ x, y }=tup;// ^^^^^^^^returnx;}// Using tc39functionfst<A,B>(tup: [A,B]){match(tup){when({ x, y }): returnx;// ^^^^^^^^}}
# Pythondeffst(tup):
matchtup:
case (x, y): returnx# ^^^^^^
// Scaladeffst[A, B](tup: (A, B)):A=
tup match {
case (x, y) => x
// ^^^^^^
}
-- Haskellfst:: (a, b) ->afst (x, y) = x
--^^^^^^
// Rustfnfst(tup:(A,B)){match tup {(x, y) => x
// ^^^^^^}}
Patterns are different from conditions. The easiest way to show this is by implementing the if then else construct using patterns.
@pokey wrote here that the patterns should be addressed by "name", "key", or "condition".
I've argued above that "condition" should refer to the "subject" and that its use for patterns is confusing.
The complexity of patterns makes it rather odd to refer to them by "name" or "key". That suggestion may have been due to the overly simplistic nature of the examples. For instance, see the following Haskell program, where I've annotated the top-most patterns. At very least, I hope that shows that "name" is inadequate?
Note: The program looks contrived, due to the fact I've copied it from a parser test, but patterns like these are extremely common in Haskell. Sometimes they use better names.
These aren't value because they're binding occurrences rather than values, so the use cases, domain and iteration scopes are very different.
These aren't key or item because they're not always in a list or map like context, and furthermore because they're binders rather than items in a list.
@pokey What do you think should be used in the JavaScript, Python and Rust examples?
I believe they're as follows, but easiest to paste them into a file, pull up the "bar cursorless" sidebar and click through the scopes to see what hits. Tho I'm guessing we don't support the tc39 one
// TypeScriptfunctionfst<A,B>(tup: [A,B]){const{ x, y }=tup;// ^^^^^^^^ <~~ namereturnx;}// Using tc39functionfst<A,B>(tup: [A,B]){match(tup){when({ x, y }): returnx;// ^^^^^^^^ <~~ condition}}
# Pythondeffst(tup):
matchtup:
case (x, y): returnx# ^^^^^^ <~~ condition
One major use case for this, the overlapping iteration scopes between formal and actual arguments, might be fixed by separating @argument.formal and @argument.actual:
-- vvv argument.actual.iteration-- v argument.actual-- v argument.actual-- v argument.actual
foo f x y = f x y
--^ argument.formal-- ^ argument.formal-- ^ argument.formal-- ^^^^^^^^^^^^^ argument.formal.iteration
Activity
wenkokke commentedon Jan 17, 2024
@pokey wrote here that the patterns should be addressed by "name", "key", or "condition".
I've argued above that "condition" should refer to the "subject" and that its use for patterns is confusing.
The complexity of patterns makes it rather odd to refer to them by "name" or "key". That suggestion may have been due to the overly simplistic nature of the examples. For instance, see the following Haskell program, where I've annotated the top-most patterns. At very least, I hope that shows that "name" is inadequate?
Note: The program looks contrived, due to the fact I've copied it from a parser test, but patterns like these are extremely common in Haskell. Sometimes they use better names.
pokey commentedon Jan 18, 2024
my thinking would be
wenkokke commentedon Jan 18, 2024
I'm not sure if item makes sense in the general case?
Are the
xandyon the left hand side still item?wenkokke commentedon Jan 18, 2024
@pokey What do you think should be used in the JavaScript, Python and Rust examples?
wenkokke commentedon Jan 18, 2024
These aren't
valuebecause they're binding occurrences rather than values, so the use cases, domain and iteration scopes are very different.These aren't
keyoritembecause they're not always in a list or map like context, and furthermore because they're binders rather than items in a list.[-]Add scope type "pattern"[/-][+]Add scope type `"pattern"`[/+][-]Add scope type `"pattern"`[/-][+]Add `"pattern"` scope type[/+]pokey commentedon Jan 18, 2024
no I think I'd call those
"arg"?pokey commentedon Jan 18, 2024
we tend to use the same scope name whether it's constructing or deconstructing. makes it easier for the ol' lizard brain that just sees shapes
pokey commentedon Jan 18, 2024
I believe they're as follows, but easiest to paste them into a file, pull up the "bar cursorless" sidebar and click through the scopes to see what hits. Tho I'm guessing we don't support the tc39 one
wenkokke commentedon Jan 19, 2024
So it's nested args all the way down? Because
(Left x)is also "arg".pokey commentedon Jan 19, 2024
In this case, yes, but note that in #2177 (comment) there's no "arg" nesting
wenkokke commentedon Jan 19, 2024
True, but item is inappropriate there, so those cases would also be "arg".
pokey commentedon Jan 19, 2024
can you elaborate?
wenkokke commentedon Jan 22, 2024
If
and
then
and
because they're all the same kind of thing.
wenkokke commentedon Jan 22, 2024
One major use case for this, the overlapping iteration scopes between formal and actual arguments, might be fixed by separating
@argument.formaland@argument.actual:pokey commentedon Jan 23, 2024
interesting. maybe let's discuss this one in meet-up?