-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSleep.hs
36 lines (30 loc) · 1002 Bytes
/
Sleep.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import qualified System.Environment as E
import qualified Control.Concurrent as C
stoint :: String -> Either String Int
stoint arg =
case reads arg :: [(Int, String)] of
{
p @ ((x, "") :xs)
-> Right $ (fst . head) p;
_
-> Left
$ "Can not parse the argument."
++ " Must contain only numbers.";
}
iter :: Int -> Int -> IO ()
iter until done =
do
if done == until
then return ()
else C.threadDelay 1000000 >> iter until (done + 1)
main = do
args <- E.getArgs
if length args /= 1
then error "Expects exactly one argument."
else do
let arg = stoint $ head args
case arg of
{
Left x -> error x;
Right x -> iter x 0;
}