/ test / contracts / sorting.aes
sorting.aes
 1  contract Sorting =
 2  
 3    // Allow sorting the state
 4    type state = list(int)
 5  
 6    entrypoint init(l : list(int)) = l
 7  
 8    stateful entrypoint state_sort() =
 9      put(sort(state))
10  
11    entrypoint sort(l : list(int)) =
12      switch(l)
13          [] => []
14          x :: xs => insert(x, sort(xs))
15  
16    entrypoint insert(x : int, l : list(int)) =
17      switch(l)
18          [] => [x]
19          y :: ys =>
20              switch(y =< x)
21                  true => y :: insert(x, ys)
22                  false => x :: l