usage of semicolon in computation expression valid, but not on a single line?
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Given this code:
```fsharp
type Monad<'t> = Monad of 't
type Builder() =
member __.Bind (x : Monad<'a>,f: 'a -> Monad<'b>) : Monad<'b> = failwith ""
member x.Zero () : Monad<'a> = failwith ""
member x.Return (v: 'a) : Monad<'a> = Monad v
let builder = new Builder()
let z = Monad ()
let ok =
builder {
do! z
return 1
}
let ok =
builder {
do! z;
return 1;
}
let nok = builder { do! z; return 1 }
```
**Actual behavior**
the `return` expression in `nok` gives:
> This construct may only be used within computation expressions. To return a value from an ordinary function simply write the expression without 'return'.
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 :
> When the semicolon is optional, **parsing inserts a $sep token automatically** and applies an additional syntax rule for lightweight syntax (§15.1.1).
Regarding computation expressions §6.3.10:
> More specifically, computation expressions have the following form:
builder-expr { cexpr } where **cexpr is, syntactically, the grammar of expressions** with the additional constructs that are defined in comp-expr.
If this is not supposed to work, is it possible to know which area of the spec would explain it?
**Known workarounds**
* [x] use the enter key more
* [ ] going with obscure point free operators
**Related information**
* maybe related: #4653
* VS2019
Contributor guide
Assessment
This issue has not been assessed yet.