aboutsummaryrefslogtreecommitdiff
path: root/comparison/OCaml/qsort800000.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/qsort800000.ml
parente273a97d97c9d163bf1ef914cb4659a2593fbdd0 (diff)
downloadinpla-2385aacb1237295a4eacade285e6bc3b542ad06f.tar.gz
inpla-2385aacb1237295a4eacade285e6bc3b542ad06f.zip
Benchmarks for OCaml
Diffstat (limited to 'comparison/OCaml/qsort800000.ml')
-rw-r--r--comparison/OCaml/qsort800000.ml30
1 files changed, 30 insertions, 0 deletions
diff --git a/comparison/OCaml/qsort800000.ml b/comparison/OCaml/qsort800000.ml
new file mode 100644
index 0000000..627abd2
--- /dev/null
+++ b/comparison/OCaml/qsort800000.ml
@@ -0,0 +1,30 @@
+let rec split pivot (alist : int list) =
+ match alist with
+ [] -> ([], [])
+ | (x::xs) ->
+ let (below, above) = split pivot xs in
+ if x<pivot then (x::below, above)
+ else (below, x::above) ;;
+
+let rec qsort (alist : int list) =
+ match alist with
+ [] -> []
+ | pivot::rest ->
+ let (below, above) = split pivot rest
+ in (qsort below) @ [pivot] @ (qsort above) ;;
+
+
+
+
+let rec mkRandList n =
+ match n with
+ 0 -> []
+ | n -> (Random.int 10000)::(mkRandList (n-1)) ;;
+
+let main = qsort (mkRandList 800000) ;;
+
+(*
+The following error arises:
+
+Stack overflow during evaluation (looping recursion?).
+*)