-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Custom number encodings which use other compiled LC terms create awkward and unnecessary "layers of eagerness".
As an example, this code creates a dummy number encoding in which every number is represented as K
. The K
is compiled as LC to retain laziness, but due to the "layer of eagerness" caused by the wrapper function around K
in Javascript, each argument to K is eagerly evaluated and so the test fails with an evaluation error.
import { assert, LC, getSolution } from "./lc-test.js";
const { K } = LC.compile(String.raw`
K = \ k _ . k
`);
const toInt = () => 0;
const fromInt = () => K;
LC.configure({ purity: "Let", numEncoding: {toInt, fromInt}, verbosity: "Concise" });
const { foo } = LC.compile(String.raw`
True = \ a _ . a
foo = 0 True ()
`);
describe("Example", () => {
it("example tests", () => {
assert.strictEqual( foo(true)(false), true );
});
});
Potential fixes would be:
a) Improve the logic of fromInt
to detect LC wrapper functions, and to use the underlying term directly (removing the eagerness layer)
b) Add an explicite alternative fromInt
which is expected to return a LC term
c) Allow fromInt
to accept strings, which it could compile itself into LC terms to use (??)