First test work commit, don't touch

This commit is contained in:
Robert Virding
2018-12-22 01:23:40 +01:00
parent 3ceb8c38db
commit d4d02fd576
97 changed files with 10599 additions and 0 deletions
+29
View File
@@ -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