-
-
Save omarkj/c36c14700eb7a5bfd775f628060a40e4 to your computer and use it in GitHub Desktop.
This file contains 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
primitive Add | |
primitive Dec | |
type AddOrDec is (Add | Dec) | |
type CmRDTCounterOp is (AddOrDec, U128) | |
class CmRDTCounter | |
var _value: U128 | |
new create() => _value = 0 | |
fun read(): U128 => | |
_value | |
fun ref add(number: U128): CmRDTCounterOp => | |
let op: CmRDTCounterOp = | |
if number >= 0 then | |
(Add, number) | |
else | |
(Dec, number) | |
end | |
apply(op) | |
op | |
fun ref apply(op: CmRDTCounterOp) => | |
match op | |
| (Add, let number: U128) => _value = _value + number | |
| (Dec, let number: U128) => _value = _value - number | |
end | |
actor Main | |
new create(env: Env) => | |
var counter = CmRDTCounter.create() | |
let op1 = counter.add(10) |
This file contains 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
~/c/b/src ❯❯❯ ponyc ⏎ | |
Building builtin -> /usr/local/Cellar/ponyc/0.10.0/packages/builtin | |
Building . -> /Users/omarkj/code/bogi/src | |
Generating | |
Reachability | |
Selector painting | |
Data prototypes | |
Data types | |
Function prototypes | |
Functions | |
[1] 25094 segmentation fault ponyc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment