練習問題
※このページの筆者はHaskellを今日初めて書きました。
変な処理があれば修正してください。
import Data.IORef -- Define 'while' while test action = do val <- test if val then do { action; while test action } else return () -- Some helpers for use with 'while' incr ref = modifyIORef ref (+1) test ref f = do { val <- readIORef ref; return (f val) } main = do ref <- newIORef 0 while (test ref (< 5)) (do { putStrLn "Hello World!"; incr ref })
module Main where main :: IO() main = printAll $ map fizzBuzz [1..100] where printAll [] = return () printAll (x:xs) = putStrLn x >> printAll xs fizzBuzz :: Integer -> String fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz" | n `mod` 5 == 0 = "Buzz" | n `mod` 3 == 0 = "Fizz" | otherwise = show n