-
-
Notifications
You must be signed in to change notification settings - Fork 84
Add keyword for alternatives in a match construct #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Good stuff thanks for filing. A couple thoughts:
|
Patterns and values are rather different and merging them might let to very confusing selections... Are you suggesting that "arg" matches the matched value when the cursor is on "match"? There could be arbitrarily nested function calls in x, so having a keyword that jumps directly to the top of the match construct might be extremely useful? |
Let's talk this one out when we discuss the haskell stuff. I like to merge when I can to keep vocabulary down but when it doesn't make sense I'm always happy to add another scope type |
I think it makes more sense to discuss this while we’re working on Rust support as rust pattern matching capabilities and syntax is more complex than that of Haskell. And it’s such an integral part of the language that I don’t see much sense adding rust support without pattern matching support. |
We should probably think about how we can make match arms consistent with case arms. Ref: #247 |
That’s probably a technical limitation, but if it isn’t I would actually allowed each language to define it’s own scopes instead of trying to define a set of common ones and having languages where not all of them are defined. Sure, there’s a lot of commonalities between PLs, but there’s also a lot of differences which would be quite hard to model properly. IMHO it doesn’t even worth trying to do this. |
General philosophy
Yes, today all languages share scope types, and that is in fact a technical limitation that we'd like to remove. Unfortunately, we're dependent on Talon RPC to make that happen, so it's tough to say when exactly we'll be able to move past that limitation However, even once we are able to have language-specific scope types, consistency is still important. For people who work in multiple languages, consistency is quite helpful. It's one of the nice things about using knausj, for example. You can use roughly the same set of commands to work in many languages. I don't think we need to be dogmatic about consistency, but I'd argue that we should only drop it if we have a good reason to do so. Match statements themselvesA case for consistencyMore concretely, in this case, I would argue that match statements and case statements are conceptually similar enough that we should align the scope types across languages. They have the same elements in all the languages we're talking about here (Python, Typescript, Haskell, and Rust):
In an attempt to reduce cognitive load, I would push for using the same scope types for each of these across languages. Proposed scope typesI would argue for the following:
In picturesFollowing your great example, @purpleP, I've taken some screenshots 😊
|
Wait, could you elaborate how Rust’s patterns are more complex? I don’t think I follow. (I do agree, though, that they’re an essential part of any language which supports them.) |
Unless some extensions were added to GHC or I am missing something Haskell’s pattern matching can only do the opposite of a type constructor, right (aside from primitive types)? It can only match against a type constructors, right? And in rust they’ve added a few additional ad-hoc features like slice patterns, guard clauses and ability to match on numeric and alphabetical ranges. |
Ohh, I didn't know about those! On the Haskell sided, boolean guards, pattern guards, pattern synonyms, record patterns, and view patterns complicate things as well. However, I think it'd make sense to start by designing for just the basic patterns on algebraic data types. |
@pokey I like your proposal. |
Ok I've edited my comment above with some new terms after a discussion with @AndreasArvidsson and @phillco. Tl;dr:
See the updated comment for discussion |
edit @pokey:
As discussed in #579 (comment), we'd like to proceed as follows:
"subject"
scope type #1172"branch"
scope type #1173"name"
/"key"
/"condition"
for switch statements #1174"value"
for switch statements #1175"inside branch"
#1176Original
There currently is no keyword for selecting alternatives in a match construct. Examples of match constructs are:
We probably want three keywords:
matched
to select the value matched on, i.e.,x
;<ordinal> pattern
to select the i’th pattern, i.e.,Alt1
toAltN
above; and<ordinal> case
to select the i’th case, i.e.,exp1
toexpN
above.Unmodified
pattern
andcase
should probably to the scopes relative to the named mark or cursor, i.e.,pattern
refers toAlt1
if the mark or cursor is in eitherAlt1
orexp1
, and similarly forcase
.The text was updated successfully, but these errors were encountered: