From 787dc13c837f0955fbd85b8f26a05d720d361333 Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Sun, 24 Oct 2021 23:04:45 +0900 Subject: Upload the comparison directory --- comparison/Haskell/msort-800000.hs | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 comparison/Haskell/msort-800000.hs (limited to 'comparison/Haskell/msort-800000.hs') diff --git a/comparison/Haskell/msort-800000.hs b/comparison/Haskell/msort-800000.hs new file mode 100644 index 0000000..eb1a24d --- /dev/null +++ b/comparison/Haskell/msort-800000.hs @@ -0,0 +1,45 @@ +{- +https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml +-} +import System.Random + +mysplit [] = ([], []) +mysplit [a] = ([a], []) +mysplit (a:b:cs) = (a:m, b:n) + where + (m,n) = mysplit cs + +merge ([], ys) = ys +merge (xs, []) = xs +merge (x:xs, y:ys) + | x IO([Int]) +randomList 0 = return [] +randomList n = do + r <- randomRIO (1,10000) + rs <- randomList (n-1) + return (r:rs) + + + +main = do + list <- randomList 800000 + let sorted = msort list + print (take 10 sorted) + + -- cgit v1.2.3