fork download
  1. import Test.QuickCheck.Gen(generate,shuffle)
  2. import Control.Monad(forM,forM_)
  3. import Control.Concurrent(newChan,writeChan,readChan,forkIO,threadDelay)
  4. import Data.Time.Clock(getCurrentTime,utctDayTime)
  5.  
  6. sleepSort unit xs = do
  7. chan <- newChan
  8. forM_ xs $ \x -> forkIO $ do
  9. threadDelay (x * unit * 1000)
  10. writeChan chan x
  11. forM xs . const $ readChan chan
  12.  
  13. main = do
  14. src <- generate . shuffle $ [1..1000]
  15. let sorted xs = and . zipWith (<=) xs $ tail xs
  16. go m = do
  17. t1 <- utctDayTime <$> getCurrentTime
  18. out <- sleepSort m src
  19. t2 <- utctDayTime <$> getCurrentTime
  20.  
  21. putStr ("m = " ++ show m ++ " ... " ++ show (t2-t1))
  22. if (sorted out)
  23. then putStrLn " (done)"
  24. else putStrLn " (failed)" >> go (m+1)
  25.  
  26. go 1
  27.  
  28. {-
  29.   m = 1 ... 1.008547611s (failed)
  30.   m = 2 ... 2.003697498s (failed)
  31.   m = 3 ... 3.004868516s (failed)
  32.   m = 4 ... 4.004364411s (failed)
  33.   m = 5 ... 5.00563169s (failed)
  34.   m = 6 ... 6.005584285s (done)
  35. -}
  36.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:1:1: error:
    Failed to load interface for ‘Test.QuickCheck.Gen’
    Use -v to see a list of the files searched for.
stdout
Standard output is empty