From 8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Mon, 2 May 2022 09:49:01 +0900 Subject: v0.8.2-1 --- comparison/Haskell/Makefile | 7 +++--- comparison/Haskell/bsort-40000.hs | 1 + comparison/Haskell/msort-260000.hs | 51 ++++++++++++++++++++++++++++++++++++++ comparison/Haskell/qsort-260000.hs | 43 ++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 comparison/Haskell/msort-260000.hs create mode 100644 comparison/Haskell/qsort-260000.hs (limited to 'comparison/Haskell') diff --git a/comparison/Haskell/Makefile b/comparison/Haskell/Makefile index 0042c28..b55259f 100644 --- a/comparison/Haskell/Makefile +++ b/comparison/Haskell/Makefile @@ -1,8 +1,7 @@ CC = stack ghc CFLAGS = -O2 BENCHMARK = bash ../tools/sptest_commands.sh -TARGET = ack3-11 fib38 bsort-40000 isort-40000 qsort-800000 msort-800000 -#TARGET = ack3-11 +TARGET = ack3-11 fib38 bsort-40000 isort-40000 qsort-260000 msort-260000 LOG = log.txt @@ -25,10 +24,10 @@ bsort-40000: bsort-40000.hs isort-40000: isort-40000.hs $(CC) -- $(CFLAGS) $< -qsort-800000: qsort-800000.hs +qsort-260000: qsort-260000.hs $(CC) -- $(CFLAGS) $< -msort-800000: msort-800000.hs +msort-260000: msort-260000.hs $(CC) -- $(CFLAGS) $< diff --git a/comparison/Haskell/bsort-40000.hs b/comparison/Haskell/bsort-40000.hs index 90f208c..c065a32 100644 --- a/comparison/Haskell/bsort-40000.hs +++ b/comparison/Haskell/bsort-40000.hs @@ -15,6 +15,7 @@ bs xs n = xs go xs 0 = xs go xs n = go (bs xs n) (n-1) +bsort [] = [] bsort xs = go xs (length xs -1) {- diff --git a/comparison/Haskell/msort-260000.hs b/comparison/Haskell/msort-260000.hs new file mode 100644 index 0000000..49cae3c --- /dev/null +++ b/comparison/Haskell/msort-260000.hs @@ -0,0 +1,51 @@ +{- +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) + + +validation [] = True +validation (x:xs) = validation_cons x xs +validation_cons x [] = True +validation_cons x (y:ys) = + if x<=y then validation_cons y ys + else False + + +main = do + list <- randomList 260000 + let sorted = msort list + print (validation sorted) diff --git a/comparison/Haskell/qsort-260000.hs b/comparison/Haskell/qsort-260000.hs new file mode 100644 index 0000000..7115121 --- /dev/null +++ b/comparison/Haskell/qsort-260000.hs @@ -0,0 +1,43 @@ +{- +(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *) +-} +import System.Random + +qsort [] = [] +qsort [x] = [x] +qsort (x:xs) = (qsort left) ++ [x] ++ (qsort right) + where (left, right) = part x xs + +part pivot [] = ([], []) +part pivot (x:xs) + | x IO([Int]) +randomList 0 = return [] +randomList n = do + r <- randomRIO (1,10000) + rs <- randomList (n-1) + return (r:rs) + + +validation [] = True +validation (x:xs) = validation_cons x xs +validation_cons x [] = True +validation_cons x (y:ys) = + if x<=y then validation_cons y ys + else False + + +main = do + list <- randomList 260000 + let sorted = qsort list + print (validation sorted) -- cgit v1.2.3