1 changed files with 23 additions and 0 deletions
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
{-# LANGUAGE NoImplicitPrelude #-} |
||||
|
||||
import Prelude (Int, IO, Maybe (Just, Nothing), String, |
||||
(.), (*), (++), |
||||
compare, flip, mapM_, putStrLn) |
||||
import Control.Concurrent (threadDelay) |
||||
import Control.Monad ((>>=), (>>)) |
||||
import Data.List (sortBy) |
||||
import System.Environment (getArgs) |
||||
import System.Exit (exitFailure) |
||||
import Text.Read (readMaybe) |
||||
|
||||
microseconds :: Int |
||||
microseconds = 1000000 |
||||
|
||||
sleep :: String -> IO () |
||||
sleep time = wait (readMaybe time) |
||||
where wait Nothing = putStrLn ("sleep: invalid time interval ‘" ++ time ++ "’") >> exitFailure |
||||
wait (Just n) = threadDelay (n * microseconds) |
||||
|
||||
main :: IO () |
||||
main = getArgs >>= mapM_ sleep . sortBy (flip compare) -- sort args to handle non-integer values firstly |
||||
|
Loading…
Reference in new issue