Skip to content

Instantly share code, notes, and snippets.

@fumieval
Created July 9, 2012 13:37
Show Gist options
  • Save fumieval/3076630 to your computer and use it in GitHub Desktop.
Save fumieval/3076630 to your computer and use it in GitHub Desktop.
Control.Monad.Trans.Loopを使ってみた
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