aboutsummaryrefslogtreecommitdiff
path: root/comparison/OCaml/msort800000.ml
diff options
context:
space:
mode:
authorShinya Sato <shinnya.sato@gmail.com>2022-04-16 20:25:55 +0900
committerShinya Sato <shinnya.sato@gmail.com>2022-04-16 20:25:55 +0900
commit2385aacb1237295a4eacade285e6bc3b542ad06f (patch)
treeeb97f25db2fd31bf2bad59d68e257abaa08c02ff /comparison/OCaml/msort800000.ml
parente273a97d97c9d163bf1ef914cb4659a2593fbdd0 (diff)
downloadinpla-2385aacb1237295a4eacade285e6bc3b542ad06f.tar.gz
inpla-2385aacb1237295a4eacade285e6bc3b542ad06f.zip
Benchmarks for OCaml
Diffstat (limited to 'comparison/OCaml/msort800000.ml')
-rw-r--r--comparison/OCaml/msort800000.ml43
1 files changed, 43 insertions, 0 deletions
diff --git a/comparison/OCaml/msort800000.ml b/comparison/OCaml/msort800000.ml
new file mode 100644
index 0000000..1835b98
--- /dev/null
+++ b/comparison/OCaml/msort800000.ml
@@ -0,0 +1,43 @@
+let rec split (alist : int list) =
+ match alist with
+ [] -> ([], [])
+ | [a] -> ([a], [])
+ | a::b::cs ->
+ let (m,n) = split cs in
+ (a::m, b::m) ;;
+
+let rec merge (alist : int list) (blist : int list) =
+ match alist with
+ [] -> blist
+ | x::xs ->
+ match blist with
+ [] -> x::xs
+ | y::ys ->
+ if x<y then x::(merge xs (y::ys))
+ else y::(merge (x::xs) ys) ;;
+
+
+let rec msort (alist : int list) =
+ match alist with
+ [] -> []
+ | a::[] -> [a]
+ | a::b::[] -> if a<b then [a;b] else [b;a]
+ | xs ->
+ let (m,n) = split xs
+ in merge (msort m) (msort n) ;;
+
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1)) ;;
+
+let main = msort (mkRandList 800000) ;;
+
+
+(*
+The following error arises:
+
+Stack overflow during evaluation (looping recursion?).
+*)