aboutsummaryrefslogtreecommitdiff
path: root/sample/isort.in
blob: e6370559a06cfd52128a0314d8690e4148f5c6a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Insertion sort

// Rules
isort(ret) >< [] => ret~[];
isort(ret) >< x:xs => insert(ret, x)~cnt, isort(cnt)~xs;

insert(ret, int x) >< [] => ret~[x];
insert(ret, int x) >< (int y):ys
| x<=y => ret~(x:y:ys)
| _    => ret~(y:cnt), insert(cnt, x)~ys;


// Nets
isort(r)~[3,6,1,9,2];
r;