We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
with val
There's no way to unpack more complex types the using with val _ = ... syntax sugar.
with val _ = ...
When working with stream, I tried to do something like:
stream
def main() = { with val (i, x) = [(1, 'a'), (2, 'b'), (3, 'c')].foreach; println(show(i) ++ ": " ++ show(x)) }
in order to unpack the tuple. However, that's wrong since this sugar would imply that foreach takes two arguments as it desugars to something like:
...foreach { (i, x) => ... }
But the correct diet, sugar-free version is the following:
def main() = [(1, 'a'), (2, 'b'), (3, 'c')].foreach { case (i, x) => println(show(i) ++ ": " ++ show(x)) }
I tried to remedy this by using Tuple2(i, x) explicitly, but that reports a parse error:
Tuple2(i, x)
def main() = { with val Tuple2(i, x) = [(1, 'a'), (2, 'b'), (3, 'c')].foreach; // ^ Expected = but got ( println(show(i) ++ ": " ++ show(x)) }
Similarly if I try to use a custom type:
record Pos(i: Int, x: Char) def main() = { with val Pos(i, x) = [Pos(1, 'a'), Pos(2, 'b'), Pos(3, 'c')].foreach; // ^ Expected = but got ( println(show(i) ++ ": " ++ show(x)) }
What does work is the following:
def main() = { with val tup = [(1, 'a'), (2, 'b'), (3, 'c')].foreach; val (i, x) = tup; println(show(i) ++ ": " ++ show(x)) }
The text was updated successfully, but these errors were encountered:
I'm also not 100% sure that we want this feature, but it's very helpful in the zip example in the PR text of #705.
zip
Sorry, something went wrong.
Here's the code responsible for parsing with val ...:
with val ...
effekt/effekt/shared/src/main/scala/effekt/RecursiveDescent.scala
Lines 198 to 204 in adf76cf
where as here's the code responsible for parsing val (a, b) = ...:
val (a, b) = ...
Lines 398 to 403 in adf76cf
No branches or pull requests
Problem statement
There's no way to unpack more complex types the using
with val _ = ...
syntax sugar.Motivation
When working with
stream
, I tried to do something like:in order to unpack the tuple.
However, that's wrong since this sugar would imply that foreach takes two arguments
as it desugars to something like:
...foreach { (i, x) => ... }
But the correct diet, sugar-free version is the following:
Possible and impossible workarounds
I tried to remedy this by using
Tuple2(i, x)
explicitly, but that reports a parse error:Similarly if I try to use a custom type:
What does work is the following:
The text was updated successfully, but these errors were encountered: