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

vine: the inverse operator #31

Merged
merged 2 commits into from
Oct 6, 2024
Merged

vine: the inverse operator #31

merged 2 commits into from
Oct 6, 2024

Conversation

tjjfvi
Copy link
Member

@tjjfvi tjjfvi commented Sep 29, 2024

The inverse operator, ~, is a fundamental primitive for Vine; features like mutable references and functions can both be implemented with it.

This also introduces the concept of a space, which is the inverse of a value; it is a space where a value can be put.

A place consists of a value and a space.

This concept of a space fills in some existing gaps in the language. For example, the assignment statement is now of the form space_expr = value_expr. (Previously, it was handled as value_pat = value_expr, like let statements, which is very incorrect.)

Similar to how the reference operator takes a place and wraps it into a value, the inverse operator can be thought of taking a space and wrapping it into a value. The inverse operator can also work on values, unwrapping them into spaces. When passed a place, the inverse operator returns another place, but the space is wrapped to be the value of the new place, and the value is unwrapped to be the space of the new place.

Also important to note is that if the inverse operator is passed a space of type T, it outputs a value of type ~T. (At least, conceptually; of course Vine does not yet have a formal type system.)

The inverse operator is an involution; ~~x is always equivalent to x.

At the Ivy level, the inverse operator is a no-op; it simply changes the way things are wired. It does, however, mean that Ivy nets are now non-polarizable. (This could be rectified, if needed, by representing the inverse with a unary node.)

See the inverse.vi test for examples of using the inverse operator to implement mutable references, functions, and variables with reversed causality.

Copy link

@vjjft vjjft left a comment

Choose a reason for hiding this comment

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

reviewed with assumed ability

@tjjfvi tjjfvi added this pull request to the merge queue Oct 6, 2024
Merged via the queue into main with commit 25940c4 Oct 6, 2024
5 checks passed
@tjjfvi tjjfvi deleted the dual branch October 6, 2024 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants