fsharp / fsharp/fslang-suggestions
Computation Expressions bug when using MaintainsVariableSpace / ProjectionParameter
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
```fsharp
type AH =
| AH
member _.For(x, f) = f x
member _.Yield x = x
[]
member _.foo(x, []y) =
let x = y x
x, "A"
[]
member _.select(src, []f) = f src
let foo (x: int) =
AH {
for x in x do
let n = x
foo (n + x)
select n
}
```
The above code compiles successfully, but the result is not the value of `n`, as intuitively expected, but `"A"`. I understand why this is the case, but can we be smarter when parsing the CE?
Because if you don't consider the implementation of CE, it is easy for users to write wrong expressions.
But if the CE implementation considers how to avoid this, there is only one conclusion: do not generate tuples.
Not generating tuples often makes some code impossible to optimize.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling the provided F# computation-expression example and confirming that it produces "A" rather than the expected value of n. Investigate how MaintainsVariableSpace and ProjectionParameter are parsed, including the tuple-generation trade-off. Done means the behavior is resolved or clearly specified without unnecessarily preventing optimization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fsharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100