fork download
  1. import Control.Monad
  2. import Control.Monad.Writer
  3. import Data.Monoid
  4.  
  5. merge :: [Int] -> [Int] -> Writer (Sum Int) [Int]
  6. merge [] ys = return ys
  7. merge xs [] = return xs
  8. merge (x:xs) (y:ys)
  9. | x <= y = do { temp <- merge xs (y:ys); return (x:temp) }
  10. | otherwise = do
  11. temp <- merge (x:xs) ys
  12. tell (Sum (length (x:xs)))
  13. return (y:temp)
  14.  
  15. mergeSort :: [Int] -> Writer (Sum Int) [Int]
  16. mergeSort [] = return []
  17. mergeSort [x] = return [x]
  18. mergeSort xs = do
  19. let (lx, rx) = splitAt (div (length xs) 2) xs
  20. slx <- mergeSort lx
  21. srx <- mergeSort rx
  22. merge slx srx
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.hs:2:8:
    Could not find module `Control.Monad.Writer'
    Perhaps you meant
      Control.Monad.Fix (from base)
      Control.Monad.Zip (from base)
    Use -v to see a list of the files searched for.
stdout
Standard output is empty