Open VictorTaelin opened 2 months ago
Mistery solved, I believe! I manually reduced this to:
(Quote
(Term/Lam λx
(DUP 0
(DUP 1 $f4
λf5λf6
(DUP 1 x λb0λb1
(Term/Sup 0 f5 (APP b0 (APP b1 (Term/Sup 1 f6 $x3))))
)
)
λf3λ$f4 (Term/Lam λ$x3(f3))
)
)
0)
(You can "verify" the correctness by running this and the original code without the Quote and seeing it has idenctical results)
If you look closely you'll see that
(DUP 0
(DUP 1 $f4
λf5λf6
(DUP 1 x λb0λb1
(Term/Sup 0 f5 (APP b0 (APP b1 (Term/Sup 1 f6 $x3))))
)
)
λf3λ$f4 (Term/Lam λ$x3(f3))
)
which is the one binding $f4
,
depends on
(DUP 1 $f4
λf5λf6
(DUP 1 x λb0λb1
(Term/Sup 0 f5 (APP b0 (APP b1 (Term/Sup 1 f6 $x3))))
)
)
which itself depends on $f4
.
Therefore we have circular dependency here, and the functions can't reduce.
I've hit a very similiar issue with my own attempt at an SIC-HOAS
Reproducing the behavior
Consider the following Bend program:
It implements a HOAS evaluator for the Interaction Calculus. When running it on Bend, for
2 ^ 2
, it outputs:I expected the result to be the encoding of
4
, sinceC2a
andC2b
use different dup labels. Yet, we get an erratic result, with a weird, unbound$b
variable shown. This could be a bug on Bend or HVM2, this could be a bug or typo on my program, or this could be some fundamental limitation on implementing HOAS IC on Interaction Combinators.I'm looking for insights.
Note: we also get the wrong result on HVM1 (Gist which makes me suspect it is either some fundamental limitation I'm overseeing, or just a silly bug in the code above. Here is the complete evaluation log (running it on HVM1). Going through this step by step might help us understand where the divergence arises.
System Settings
Bend 0.2.36, OSX Sonoma 14.5.