Skip to content
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

Make Expr type explicit, add Literal constructor #20

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

rvs314
Copy link
Contributor

@rvs314 rvs314 commented Jul 8, 2024

This adds Expr as a union of either Variables, Terms or Literals, the last of which being a new protocol with a default implementation. The new constructor makes sure we can distinguish terms-as-values vs terms-as-terms (Literal[Term[A]] != Term[A]).

@rvs314 rvs314 requested a review from eb8680 July 8, 2024 13:46
Copy link
Contributor

@eb8680 eb8680 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename Literal to e.g. Atom or Constant so that it doesn't collide with typing.Literal?

@rvs314
Copy link
Contributor Author

rvs314 commented Jul 8, 2024

Can you rename Literal to e.g. Atom or Constant so that it doesn't collide with typing.Literal?

That makes sense - I've renamed it to Constant

@rvs314 rvs314 force-pushed the add-literal-protocol branch from d98811f to 83deb5e Compare July 8, 2024 13:54
@rvs314 rvs314 requested a review from eb8680 July 8, 2024 19:42
@rvs314 rvs314 self-assigned this Jul 9, 2024
Copy link
Contributor

@eb8680 eb8680 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to merge this for now because it's more correct than the current version, but I think to correctly support higher-order syntax we might actually want Expr = Term[T] | T where variable contexts are determined by typing rules associated with each Operation. (In that approach, Variable is an Operation with a typing rule that introduces a fresh variable in its result context).

That's how things work in Funsor, and I think that's standard in literature on generalized algebraic theories.

@eb8680 eb8680 merged commit 87f9b06 into master Jul 10, 2024
2 of 3 checks passed
@eb8680 eb8680 deleted the add-literal-protocol branch July 10, 2024 13:55
@rvs314 rvs314 mentioned this pull request Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants