pony-tutorial
pony-tutorial copied to clipboard
Receiver capabilities of constructors not documented
- [ ] Meaning of e.g.
new ref create()should be explained. - [ ] It was mentioned on irc that
new val create()would only accept sendable arguments. This should also be documented. - [ ]
I assume thatfun val foo()would also only accept sendable arguments. I don't think this is documented either. - [ ] Probably should add further explanation of default reference capability for a type and how it differs from using a constructor with a certain receiver capability.
I assume that
fun val foo()would also only accept sendable arguments. I don't think this is documented either.
Actually, this one isn't a requirement. The reason we have that requirement for new val create is because it's roughly equivalent to a recover statement - the fields of the constructor are mutable inside the constructor body, but once it returns, the object is lifted to val. We have to require sendable arguments there for the same reason a recover statement can only allow sendable references from outside the block to be used inside the block - because otherwise a non-sendable could get embedded in the recovered sendable object, breaking capability safety.
For fun val this is not a problem because the receiver is treated as val inside the method body, so you can't assign anything to it or do anything else that break capabilities.
Thoughts on where this would go @jemc?
It was mentioned on irc that
new val create()would only accept sendable arguments. This should also be documented.The reason we have that requirement for
new val createis because it's roughly equivalent to arecoverstatement - the fields of the constructor are mutable inside the constructor body, but once it returns, the object is lifted toval.
Assuming class fields can’t be assigned from in a constructor (and noting that assigning from sendable arguments to non-sendable arguments is illegal), then I presume one of the reasons for not making an exception for constructor arguments which are only assigned to instead of assigned from, is because constructors really shouldn’t be encouraged to have side-effects? If so, then for consistency shouldn’t constructors (of all capability types) be forced to never assign to input arguments (or at least those which aren’t assigned from)?
I contemplated whether Pony has a feature to enforce referential transparency orthogonal to necessary degrees-of-freedom for reference capabilities. I pondered whether a function that takes mutable reference capabilities could possibly be referentially transparent. Contemplated whether conflating reference capabilities and referential transparency invariants would reduce degrees-of-freedom. Although a function which leaks a mutable reference capability in its return value is I guess not referentially transparent because the return value can mutate. Thus I guess box, val and tag arguments do cover the referentially transparent cases.
@SeanTAllen - I'm not sure the best place to put this, to be honest. We introduce methods and the idea of fun ref very early in the tutorial before we talk about reference capabilities at all, and we never really come back to talking about how receiver capabilities work in detail, for either for fun or new.
We probably need to add a new page to the "Reference Capabilities" section called "Receiver Capabilities" we talk about how receiver capabilities work in detail, for both fun and new.
Great issue!
Closest mention of receivers is in viewpoint adaptation: tutorial.ponylang.io/reference-capabilities/arrow-types.html
I think this needs to be after the introduction of refcaps and before viewpoint adaptation so perhaps around "Passing and Sharing References" is a good fit? Start with (re)emphasis that anything which can be assigned to a variable has a refcap and therefore when calling methods there is an implied access to the receiver -- then this would allow discussion of constructors without seeming out of place by stating the constructor sets the capabilities of the receiver.
I recall a conversation on Zulip about this being undocumented. (Will need to snag the link later). That might help steer how people think about this idea before they know how it is really done.
On Mon, Jun 15, 2020, 11:51 AM Joe Eli McIlvain [email protected] wrote:
@SeanTAllen https://github.com/SeanTAllen - I'm not sure the best place to put this, to be honest. We introduce methods and the idea of fun ref very early in the tutorial before we talk about reference capabilities at all, and we never really come back to talking about how receiver capabilities work in detail, for either for fun or new.
We probably need to add a new page to the "reference capabilities" section called "receiver capabilities" we talk about how receiver capabilities work in detail, for both fun and new.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ponylang/pony-tutorial/issues/212#issuecomment-644249920, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJJ6P74TN6AYMYHYUJXSI3RWZGSXANCNFSM4DU27PLQ .