aboutsummaryrefslogtreecommitdiff
path: root/comparison/SML
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--comparison/SML/Makefile2
-rw-r--r--comparison/SML/bsort-40000.sml3
-rw-r--r--comparison/SML/dummy.sml55
-rw-r--r--comparison/SML/msort-260000.sml55
-rw-r--r--comparison/SML/qsort-260000.sml41
5 files changed, 154 insertions, 2 deletions
diff --git a/comparison/SML/Makefile b/comparison/SML/Makefile
index 8520e9d..0e4e2e3 100644
--- a/comparison/SML/Makefile
+++ b/comparison/SML/Makefile
@@ -1,5 +1,5 @@
COMMAND = sml
-TARGET = ack3-11.sml fib38.sml bsort-40000.sml isort-40000.sml qsort-800000.sml msort-800000.sml
+TARGET = dummy.sml ack3-11.sml fib38.sml bsort-40000.sml isort-40000.sml qsort-260000.sml msort-260000.sml
BENCHMARK = bash ../tools/sptest_scripts.sh
LOG = log.txt
diff --git a/comparison/SML/bsort-40000.sml b/comparison/SML/bsort-40000.sml
index 5e6e98b..d9e1a00 100644
--- a/comparison/SML/bsort-40000.sml
+++ b/comparison/SML/bsort-40000.sml
@@ -12,7 +12,8 @@ fun go xs 0 = xs
| go xs n = go (bs xs n) (n-1);
-fun bsort xs = go xs (length(xs) - 1);
+fun bsort [] = []
+ | bsort xs = go xs (length(xs) - 1);
(* Creates a random list *)
diff --git a/comparison/SML/dummy.sml b/comparison/SML/dummy.sml
new file mode 100644
index 0000000..15ff263
--- /dev/null
+++ b/comparison/SML/dummy.sml
@@ -0,0 +1,55 @@
+(* https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml *)
+
+fun split [] = ([], [])
+ | split [a] = ([a], [])
+ | split (a::b::cs) =
+ let
+ val (m,n) = split cs
+ in
+ (a::m, b::n)
+ end;
+
+fun merge ([], ys) = ys
+ | merge (xs, []) = xs
+ | merge (x::xs, y::ys) =
+ if x<y then
+ x::merge(xs, y::ys)
+ else
+ y::merge(x::xs, ys);
+
+fun msort [] = []
+ | msort [a] = [a]
+ | msort [a,b] = if a<b then [a,b] else [b,a]
+ | msort xs =
+ let
+ val (m,n) = split xs;
+ in
+ merge (msort m, msort n)
+ 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(msort (mkRandList 10));
+
diff --git a/comparison/SML/msort-260000.sml b/comparison/SML/msort-260000.sml
new file mode 100644
index 0000000..754ef2f
--- /dev/null
+++ b/comparison/SML/msort-260000.sml
@@ -0,0 +1,55 @@
+(* https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml *)
+
+fun split [] = ([], [])
+ | split [a] = ([a], [])
+ | split (a::b::cs) =
+ let
+ val (m,n) = split cs
+ in
+ (a::m, b::n)
+ end;
+
+fun merge ([], ys) = ys
+ | merge (xs, []) = xs
+ | merge (x::xs, y::ys) =
+ if x<y then
+ x::merge(xs, y::ys)
+ else
+ y::merge(x::xs, ys);
+
+fun msort [] = []
+ | msort [a] = [a]
+ | msort [a,b] = if a<b then [a,b] else [b,a]
+ | msort xs =
+ let
+ val (m,n) = split xs;
+ in
+ merge (msort m, msort n)
+ 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(msort (mkRandList 260000));
+
diff --git a/comparison/SML/qsort-260000.sml b/comparison/SML/qsort-260000.sml
new file mode 100644
index 0000000..40bf8b7
--- /dev/null
+++ b/comparison/SML/qsort-260000.sml
@@ -0,0 +1,41 @@
+fun quicksort nil = nil
+ | quicksort (pivot :: rest) =
+ let
+ fun split(nil) = (nil,nil)
+ | split(x :: xs) =
+ let
+ val (below, above) = split(xs)
+ in
+ if x < pivot then (x :: below, above)
+ else (below, x :: above)
+ end;
+ val (below, above) = split(rest)
+ in
+ quicksort below @ [pivot] @ quicksort above
+ 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(quicksort(mkRandList 260000));