-
Notifications
You must be signed in to change notification settings - Fork 15
handle free variables correctly #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* Introduce `Context` to define free variables for parsing and display * Add `parse_with_context` to to resolve free variables based on a `Context` * Add `Term::with_context` for displaying terms using a given `Context`
ljedrz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this feature is long overdue in this repo; would you like to fix the clippy warnings and consider one suggestion I've left?
Thanks!
Accepting a slice is more flexible and idiomatic than a vector reference (@ljedrz) Co-authored-by: ljedrz <3750347+ljedrz@users.noreply.github.com>
ce708a6 to
1f59337
Compare
|
@ljedrz While I was at it, I also fixed a couple of other pre-existing lints in unrelated code (b8a8145, 1f59337), following the "Boy Scout Rule". These additional cleanups are not essential to this PR, so if you'd prefer a more focused commit history, I am perfectly happy to revert them. Just let me know! |
ljedrz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks again!
Our current implementation of Term doesn't have free variable names as it is only a De Bruijn index expression, which is not correct. Free variable names are critical for open terms.
The issue is demonstrated by the following test, where free variable names were lost completely:
lambda_calculus/tests/reduction.rs
Line 62 in c961a86
This PR introduces a naming Context to give names to free variables, which is the same approach as the TAPL book.
Notes
A key inspiration for this change is the original TAPL implementation, which uses a top-level syntax to define variables (see https://github.com/mspertus/TAPL/blob/main/untyped/test.f ). In that implementation, you first have to define a variable like
x(usingx/;), which pushesxinto the naming context. Then, you can usexas a free variable.Since our implementation does not have such a top-level syntax, this PR introduces a Context type instead, which must be prepared manually by the user.