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

Better operators to prevent reference collapsing #76

Open
Zettelkasten opened this issue Jan 6, 2022 · 0 comments
Open

Better operators to prevent reference collapsing #76

Zettelkasten opened this issue Jan 6, 2022 · 0 comments

Comments

@Zettelkasten
Copy link
Owner

For example to implement a linked list, you could define

struct List[T] {
  head: None|Ref[Node[T]]
}
struct Node[T] {
  value: T
  next: None|Ref[Node[T]]
}

If there was a func _next[T](list: List[T]) -> Ref[None|Ref[Node[T]], you could use it for insertion:

func insert[T](list: List[T], value: T) {
  new_node: Ref[Node[T]] =? new(Node(value, None()))  # not collapsing, i.e. keeping the Ref   # 
  _next(list) =? new_node  # assign the Ref[Node[T]] into the None|Ref[Node[T]] reference returned by `_next`
}

Here with =? I mean some operator not implemented yet.

We have two cases here:

  1. Local[Ref[T]] = Ref[T]
  2. Ref[Ref[T]] = Ref[T]

I think case 1 is simple to solve: We can add a "do not collapse" operator, which collapses all Ref, but not the local variable reference (here: Local).

Case 2 is more difficult: We want to collapse one layer of the Ref, but not the other one. In general, for assignments, you would want only the single, most outer Ref to collapse. I'm not sure yet how to handle that.

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

No branches or pull requests

1 participant