Update cycle error message

This commit is contained in:
imaqtkatt 2024-03-12 13:43:52 -03:00
parent 0271739d9f
commit 58ee6c732b
6 changed files with 14 additions and 9 deletions

View File

@ -17,7 +17,7 @@ Nat.add = (Y λaddλaλb match a {
main = (Nat.add (S (S (S Z))) (S Z))
```
Because of that, is recommended to use [supercombinator](https://en.wikipedia.org/wiki/Supercombinator) formulation to make terms be unrolled lazily, preventing infinite expansion in recursive function bodies.
Because of that, its recommended to use a [supercombinator](https://en.wikipedia.org/wiki/Supercombinator) formulation to make terms be unrolled lazily, preventing infinite expansion in recursive function bodies.
The `Nat.add` definition below can be a supercombinator if linearized.

View File

@ -30,7 +30,10 @@ fn pretty_print_cycles(cycles: &[Vec<Ref>]) -> String {
cycles
.iter()
.enumerate()
.map(|(i, cycles)| format!("Cycle {}: {}", 1 + i, cycles.join(" -> ")))
.map(|(i, cycle)| {
let cycle_str = cycle.iter().chain(cycle.first()).cloned().collect::<Vec<_>>().join(" -> ");
format!("Cycle {}: {}", 1 + i, cycle_str)
})
.collect::<Vec<String>>()
.join("\n")
}

View File

@ -5,7 +5,8 @@
(H) = (I)
(I) = (H)
(M) = (N)
(N) = (M)
(N x) = (x (N x))
(M) = (M)
(Main) = *

View File

@ -3,6 +3,6 @@ source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/a_b_c.hvm
---
Mutual recursion cycle detected in compiled functions:
Cycle 1: A -> B -> C
Cycle 1: A -> B -> C -> A
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.

View File

@ -3,8 +3,9 @@ source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/multiple.hvm
---
Mutual recursion cycle detected in compiled functions:
Cycle 1: A -> B -> C
Cycle 2: H -> I
Cycle 3: M -> N
Cycle 1: A -> B -> C -> A
Cycle 2: H -> I -> H
Cycle 3: M -> M
Cycle 4: N -> N
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.

View File

@ -3,6 +3,6 @@ source: tests/golden_tests.rs
input_file: tests/golden_tests/mutual_recursion/odd_even.hvm
---
Mutual recursion cycle detected in compiled functions:
Cycle 1: isEven -> isOdd
Cycle 1: isEven -> isOdd -> isEven
This program will expand infinitely in strict evaluation mode.
Read https://github.com/HigherOrderCO/hvm-lang/blob/main/docs/lazy-definitions.md for more information.