First test work commit, don't touch
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user