2019-12-10 17:47:31 +04:00
|
|
|
type storage = int;
|
|
|
|
|
|
|
|
/* variant defining pseudo multi-entrypoint actions */
|
|
|
|
|
|
|
|
type action =
|
|
|
|
| Increment(int)
|
|
|
|
| Decrement(int);
|
|
|
|
|
|
|
|
let add = (a: int, b: int): int => a + b;
|
|
|
|
let sub = (a: int, b: int): int => a - b;
|
|
|
|
|
|
|
|
/* real entrypoint that re-routes the flow based on the action provided */
|
|
|
|
|
2020-01-09 00:58:26 +04:00
|
|
|
let main2 = (p: action, storage) => {
|
2019-12-10 17:47:31 +04:00
|
|
|
let storage =
|
|
|
|
switch (p) {
|
|
|
|
| Increment(n) => add(storage, n)
|
|
|
|
| Decrement(n) => sub(storage, n)
|
|
|
|
};
|
|
|
|
([]: list(operation), storage);
|
|
|
|
};
|
2020-01-09 00:58:26 +04:00
|
|
|
|
|
|
|
let main = (x: (action, storage)) => main2(x[0],x[1]);
|