Incorrect behavior of section parameters for recursive functions.
- Dominant language
- OCaml
- Stars
- 45
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
The following code outputs five zeros to stdout, which is counter-intuitive.
```
parameter ~a : Int
let rec print (n : Int) =
if n == 0 then ()
else (
printStrLn ~a.toString;
let ~a = ~a + 1 in
print (n-1))
let _ = print {~a=0} 5
```
This is because current implementation assumes that parameters (declared with `parameter`) of recursive functions cannot change during recursive calls. We could allow them to change (or more precisely, to appear in the less-polymorphic scheme). However, implementing such a behavior is more challenging, because we have to generate code that applies function to these parameters before we can decide which of them should be generalized. Maybe simpler algorithm that generalizes all of them could be implemented as a temporary solution.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the issue's recursive-function example and tracing how `parameter` values are generalized across recursive calls. Inspect the compiler's handling of section parameters and recursive function schemes; done means the example no longer prints five zeros and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100