From e18b27f43ac23689822d4aaaaa3e8d550e41017a Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Mon, 30 May 2022 20:36:38 +0900 Subject: v0.8.2-2 --- comparison/SML/isort-20000.sml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 comparison/SML/isort-20000.sml (limited to 'comparison/SML/isort-20000.sml') diff --git a/comparison/SML/isort-20000.sml b/comparison/SML/isort-20000.sml new file mode 100644 index 0000000..d3648cc --- /dev/null +++ b/comparison/SML/isort-20000.sml @@ -0,0 +1,35 @@ +(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *) +fun insertsort [] = [] + | insertsort (x::xs) = + let fun insert (x, []) = [x] + | insert (x, y::ys) = + if x<=y then x::y::ys + else y::insert(x, ys) + in insert(x, insertsort xs) + end; + + +(* Creates a random list *) +local + val nextInt = Random.randRange(1,10000); + val r = Random.rand(1,1); +in + fun mkRandList 0 = [] + | mkRandList n = (nextInt r)::(mkRandList (n-1)) +end; + + +(* Validation checks *) +fun validation [] = true + | validation (x::xs) = + let fun validation_cons x [] = true + | validation_cons x (y::ys) = + if x<=y then validation_cons y ys + else false + in + validation_cons x xs + end; + + +(* Main *) +validation(insertsort(mkRandList 20000)); -- cgit v1.2.3