
* Allow block with separate type signature and definition of a function For instance, ``` function add : (int, int) => int add(x, y) = x + y ``` cc #196 * Allow pattern matching in left-hand sides * Changelog * Fix type spec * partial case-on-constructor * Changelog for pattern-matching lets
29 lines
639 B
Plaintext
29 lines
639 B
Plaintext
// Testing more interesting state types
|
|
contract Stack =
|
|
|
|
type stack('a) = list('a)
|
|
|
|
record state = { stack : stack(string),
|
|
size : int }
|
|
|
|
entrypoint init(ss : list(string)) = { stack = ss, size = length(ss) }
|
|
|
|
function
|
|
length([]) = 0
|
|
length(_ :: xs) = length(xs) + 1
|
|
|
|
stateful entrypoint pop() : string =
|
|
switch(state.stack)
|
|
s :: ss =>
|
|
put(state{ stack = ss, size = state.size - 1 })
|
|
s
|
|
|
|
stateful entrypoint push(s) =
|
|
put(state{ stack = s :: state.stack, size = state.size + 1 })
|
|
state.size
|
|
|
|
entrypoint all() = state.stack
|
|
|
|
entrypoint size() = state.size
|
|
|