Skip to content

Instantly share code, notes, and snippets.

@omarkj
Last active January 11, 2017 05:19
Show Gist options
  • Save omarkj/c36c14700eb7a5bfd775f628060a40e4 to your computer and use it in GitHub Desktop.
Save omarkj/c36c14700eb7a5bfd775f628060a40e4 to your computer and use it in GitHub Desktop.
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)
~/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