Created
April 18, 2018 21:18
-
-
Save christineponyl/ed4bb2f640b17253216fc861c3dee8c6 to your computer and use it in GitHub Desktop.
Shared via Pony Playground (https://playground.ponylang.org/?gist=ed4bb2f640b17253216fc861c3dee8c6&branch=regions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter | |
var value: U32 = 0 | |
fun ref increment(delta: Delta ref) => | |
value = value + 1 | |
delta.diff = delta.diff + 1 | |
class Delta | |
var diff: U32 = 0 | |
var foo: Any box = None | |
actor Main | |
new create(env: Env) => | |
var counter : Counter iso = Counter | |
var delta : Delta iso = Delta | |
counter = recover | |
let counter' : Counter ref = consume counter | |
delta = recover | |
let delta' : Delta ref = consume delta | |
// counter' and delta' are both ref, but in different regions | |
// The compiler will ensure they stay separated | |
// For example this does not work | |
// delta'.foo = counter' | |
// This is not allowed yet, because method calls assume receiver and all arguments have the same region | |
// With some annotations on increment's definition we could specify that we allow them to come from distinct regions | |
// counter'.increment(delta') | |
// Note that for sendable caps regions are ignored. | |
// This works | |
counter'.value = counter'.value + delta'.diff | |
delta' | |
end | |
counter' | |
end | |
// counter and delta have been recovered back to iso, and can be sent away |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment