2018-12-22 01:23:40 +01:00

30 lines
650 B
Plaintext

// Testing more interesting state types
contract Stack =
type stack('a) = list('a)
record state = { stack : stack(string),
size : int }
function init(ss : list(string)) = { stack = ss, size = length(ss) }
private function length(xs) =
switch(xs)
[] => 0
_ :: xs => length(xs) + 1
stateful function pop() : string =
switch(state.stack)
s :: ss =>
put(state{ stack = ss, size = state.size - 1 })
s
stateful function push(s) =
put(state{ stack = s :: state.stack, size = state.size + 1 })
state.size
function all() = state.stack
function size() = state.size