-
Notifications
You must be signed in to change notification settings - Fork 8
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
Match
statement (syntax sugar)
#726
Comments
I was thinking about #639 but the problem is you still have to have all the incoming connections noise (and it doesn't make match specifically universal, like in Rust)
|
Given time limitations and what we understand so far I think we need to make a decision:
Example:
|
Pattern MatchingHow all this plays with #747? |
close in favor of #805 |
See #724 and #725 for context
Before (desugared)
After (sugar)
???
Note about Rust
In Rust
match
is very universal thing - it can replace bothif-else
andswitch
. It's an expression that always returns some value, but actually you don't have to return anything from your branches, it will returnunit
in that case (thinkvoid
), so it's possible to use it for both "selecting" and "routing" (triggering control-flow branch).Also checkout https://doc.rust-lang.org/book/ch18-00-patterns.html
Implementation Info
If match is only selector, then it's basically a map between senders!
If it's router (but Switch is more suitable for that and we still need selector), then it would be basically map of senders to receivers
(note that sender is one, but receivers are slice (only router, for selector it's 1-1))
On outgoing
->
Based on previous point of view we do need outgoing
->
for selector, and we do not need it for router.Since in Rust it's both, it's possible to imagine that in some cases we use
match
as selector and in some as router (kinda similar to assigning returned value from match to a variable in Rust)Selector
On incoming
->
Regardless being selector or router (which affect outgoing
->
), incoming arrow might be or might not be present, depending on whether want match to be part of the chained connection (only) or notIncoming
->
is presentFor struct selectors motivation was to allow having different selectors on different multiple receivers:
Which wasn't possible with selector as a modified for sender
v
is used twice here, and sender must not be reused. It maybe possible to teach desugarer to handle this withv -> fanOut -> [.x, .y]
, but that's much more complicated than existing implementation.In this case
match
is sender, that (just like struct selector) is only allowed as a chain-head.Which means this syntax only support match as a selector, but not as a router. Because sender must have receiver side and router doesn't have single receiver side to have after outgoing
->
.It also means for
Switch
syntax, that it cannot be implemented like this. Switch has to be receiver-side thing.It also means that
match
as both selector and router at the same time is hard to implement because it has to be supported at both sender and receiver sides.Match vs Ternary and Switch vs If-Else
Match can replace ternary (as it's more powerful form) and switch can replace if-else (in the same way). But ternary is probably more ergonomic that match. It's questionable if we can say that about switch with if-else.
The text was updated successfully, but these errors were encountered: