It’s not clear from the examples how the ownership model works with fields. If I destructively read a field that is a pointer, does it make the field null? How do I then deal with all of the nulls everywhere?

Hi, author here.
I don’t know! Haven’t gotten that far yet. What do you think would make most sense?

I’m imagining two options:

type Node {
left *Node
right *Node
}
fun option_1_a(n Node) {
let a = n.left // moves value to a
n.left // error: n.left is dead
somefun(n) // error: n is partially dead
} // drop(n.right), drop(a)
fun option_1_b(n &Node) { // n is a reference
let a = n.left // error: cannot move borrowed value
}
fun option_2_a(n Node) {
let a = n.left // error: cannot move pointer field
let b = &n.left // ok; references the field (&Node)
let c = mut&n.left // ok since n is mutable (mut&Node)
} // drop(n.right), drop(n.left)
fun option_2_b(n &Node) { // n is a reference
let b = &n.left // ok; references the field (&Node)
let c = mut&n.left // error: mut. ref to immutable value
}

Pony addresses this by making = a kind of swap, so a=b stores b in a and evaluates to the old value of a. This makes it fairly concise to preserve linear types. The problem with your first option is that it is dynamic state that needs to be tracked and isn’t expressed in your type system. The type of n.left is not actually Node*, it’s Node* | Invalid, but the Invalid option is ephemeral state. This leads to the kind of situation where you have some expressions that you can’t outline. Effectively, your scope must destroy n.

It’s not clear from the examples how the ownership model works with fields. If I destructively read a field that is a pointer, does it make the field null? How do I then deal with all of the nulls everywhere?

Hi, author here. I don’t know! Haven’t gotten that far yet. What do you think would make most sense?

I’m imagining two options:

Pony addresses this by making

`=`

a kind of swap, so`a=b`

stores`b`

in`a`

and evaluates to the old value of`a`

. This makes it fairly concise to preserve linear types. The problem with your first option is that it is dynamic state that needs to be tracked and isn’t expressed in your type system. The type of`n.left`

is not actually`Node*`

, it’s`Node* | Invalid`

, but the`Invalid`

option is ephemeral state. This leads to the kind of situation where you have some expressions that you can’t outline. Effectively, your scope must destroy`n`

.Very interesting, making “=“ a kind of swap operation!

Surprised this isn’t for the Compis. COMAL 4 lyfe!

https://github.com/rsms/compis/blob/main/README.md

:–)