Created
July 9, 2012 13:37
-
-
Save fumieval/3076630 to your computer and use it in GitHub Desktop.
Control.Monad.Trans.Loopを使ってみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.Trans.Loop | |
import Control.Applicative | |
import Control.Monad.Base | |
import System.Time | |
import System.Posix.Unistd | |
fizzbuzz n = case (mod n 3, mod n 5) of | |
(0, 0) -> "FizzBuzz" | |
(_, 0) -> "Fizz" | |
(0, _) -> "Buzz" | |
(_, _) -> show n | |
-- 1秒ごとにfizzbuzzを出力する。現在の時刻が00秒になったら終了 | |
main = foreach [0..] $ \i -> do | |
time <- liftBase $ toUTCTime <$> getClockTime | |
if ctSec time == 0 | |
then exit | |
else liftBase $ do | |
putStrLn $ fizzbuzz i | |
usleep 1000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment