SHARE
TWEET

pMergeSort

tdct Nov 19th, 2019 (edited) 146 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Parallel.Strategies
  2.  
  3. merge :: (Ord a) => [a] -> [a] -> [a]
  4. merge xs [] = xs
  5. merge [] ys = ys
  6. merge (x:xs) (y:ys)
  7.     | x <= y =  x : merge xs (y:ys)
  8.     | otherwise = y : merge (x:xs) ys
  9.  
  10. pairList :: [[a]] -> [([a], [a])]
  11. pairList (x1:x2:xs) = (x1, x2) : pairList xs
  12. pairList (x:xs) = [(x, [])]
  13. pairList [] = []
  14.  
  15. sort :: (Ord a) => [a] -> [a]
  16. sort xs = k . map (:[]) $ xs where
  17.     f = parMap rpar (uncurry merge)
  18.     k [x] = x
  19.     k xs = k . f . pairList $ xs
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top