-
Notifications
You must be signed in to change notification settings - Fork 815
usage of semicolon in computation expression valid, but not on a single line? #7261
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
The tricky thing about this is that it's ambiguous if you mean to actually |
@cartermp, thanks for the feedback. For me, this code sample fails the principle of least surprise, but I lack the context as to what the/an ambiguous cases would look like. What would be ambiguous if my code sample was compiling? Or do you have any example of something which compiles today but potentially not to the same thing if my example was compiling. Do we agree that a change done to make my sample compile would better respect the intent of the specification? Can we have a tag for specification ambiguity or something akin to it? |
Sorry, I think I'm mistaken in calling this an ambiguity. I was referring more to user behavior, but that's not really meaningful here. I think that your sample generally should be as you intend it. That is, This isn't well-specified IMO, or if it is, then the implementation is kind of wonky, since today a warning is emitted suggesting to let f x = async { return 12 } |> Async.Ignore
let g =
async {
do! f 12; f 13
}
let h =
async {
do! f 12
return 13
} Today you get a warning. And if |
@cartermp, I think there is something I had wrong intuition about: for i in 1..2 do printfn $"{i}";printfn $"{i}"; My expectation would be that the second printfn statement falls out of the scope of the one liner for loop. This expectations stems from C derived languages where you can omit braces and have the first semicolon ended statement terminate the block. In that frame, I gather that my original code would desugar into let nok = builder {
do!
z;
return 1
} Which indeed yields the same as the one liner. So I'm not sure how we can improve on this, beside finding a better way to guide people that trip on this in the error message. |
The trouble, as noted on Slack, is how the grammar slices - and while it can be defined as 'ambiguous' - it's perhaps more that the spec isn't explicit about the precedence of rules (supposing it should and needs to be). The trouble is in the question of where do the expressions begin and end. And this is the crux of things. According to the layout in the spec, a With the admittedly small chance that an upgrade to the spec will help the majority of users (who likely don't dig into the spec to understand warnings) - perhaps a more universal solution would be to try to improve error messaging around this particular error in the case that semicolons have been explicitly used, rather than implicitly inserted by the compiler. |
I ran into the same issue as @smoothdeveloper and luckily found this discussion.
is the same as
and
is the same as
I would expect the same to be possible for computation expressions. However, while
can be rewritten as
there seems to be no way to rewrite
in a single line. Parenthesis don't work. Trying
results in compiler error 792. |
Curiously, the semantics of computation expressions given here provides |
This SO question looks similar, although it's a |
Given this code:
Actual behavior
the
return
expression innok
gives:This seems like a fallback message when failing to parse the CE.
Expected behavior
I'd expect it to work fine, but probably missing something in the spec, those are the points making me feel it should work:
Regarding semicolon §6.5.2 :
Regarding computation expressions §6.3.10:
If this is not supposed to work, is it possible to know which area of the spec would explain it?
Known workarounds
Related information
The text was updated successfully, but these errors were encountered: