From 6b3075d90d945d5e7e8fd4d28284ffd99dbeb82e Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Fri, 24 Sep 2021 16:42:54 +0900 Subject: v0.4.1 --- sample/bsort.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sample/bsort.in (limited to 'sample/bsort.in') diff --git a/sample/bsort.in b/sample/bsort.in new file mode 100644 index 0000000..7b2e2d6 --- /dev/null +++ b/sample/bsort.in @@ -0,0 +1,18 @@ +// Bubble sort + +// Rules +bsort(ret) >< [] => ret~[]; +bsort(ret) >< x:xs => bsort(ret)~cnt, bubble(cnt, x)~xs; +bsort(ret) >< M(x) => ret~x; + +bubble(ret, int x) >< [] => ret~M([x]); +bubble(ret, int x) >< M(w) => ret~M(x:w); +bubble(ret, int x) >< (int y):ys +| x ret~(x:cnt), bubble(cnt, y)~ys +| _ => ret~(y:cnt), bubble(cnt, x)~ys; + + +// Nets +bsort(r)~[3,6,1,9,2]; +r; + -- cgit v1.2.3