Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I would love a better explanation for `~~x = x`. I first understood `~x` as an equivalent of an unresolved future.

Would one be able to model `~x` with, say, Rust channels?



In interaction nets, one of the core primitives is the 'wire', which form the edges in the graph. One can think of a wire as like a one-shot channel; it has a 'producer' side, which sends some value across, and a 'consumer' side, which does something with that value.

In that context, then, the inverse operator switches which side of the wire you're talking about. If you have a parameter of type `N32`, you're on the 'consumer side'. But if you have a parameter of type `~N32`, that can be viewed as being the 'producer side' of an `N32` channel. Since `~` just swaps the sides, `~~T` is the same as `T`.


Is it possible to put the 'producer side' into a 'consumer side' of another wire?

Should ~ be considered part of the type signature? Does `let ~x = y` work as destructuring?


> Is it possible to put the 'producer side' into a 'consumer side' of another wire?

Yes; you can take the producer side of an `N32` wire `x` and link it to the consumer side of an `N32` wire `y`; that just means that the value that is sent across `y` will be sent across `x`.

> Should ~ be considered part of the type signature? Does `let ~x = y` work as destructuring?

In `let ~x = y`, the `~` is part of the pattern, and is destructuring, yes. So assuming `y` is some `~N32`, that statement declares a new variable `x`, with no initial value, and whatever the final value of `x` is, that's what passed along the wire. So re: what happens when a variable is assigned more than once, the last assignment wins.


What happens when a variable is assigned more than once?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: