dotnet / dotnet/fsharp

Recursive sequence expression containing recursive definition doesn't run in finite space

Open
#996 3 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-StateMachines Feature Improvement Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

This small example causes a stack overflow, but shouldn't:

```
let rec loop r = seq {
if r > 0 then
let rec unused() = unused()
yield r
yield! loop r
}

printfn "%i" (Seq.nth 10000000 (loop 1))
```

Removing the conditional or replacing the unused recursive definition with an unused non-recursive definition both appear to result in the expected behavior of constant stack space usage.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.