Last active
February 26, 2019 02:45
-
-
Save clementi/d69ccd5867a2ae04dcfba9f6b952af2b to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell (one way to do it)
This file contains 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
module Main where | |
import Control.Monad (forM_) | |
import System.Environment (getArgs) | |
printFizzBuzz :: Integral a => a -> IO () | |
printFizzBuzz n | |
| n `mod` 3 == 0 && n `mod` 5 == 0 = putStrLn "FizzBuzz" | |
| n `mod` 3 == 0 = putStrLn "Fizz" | |
| n `mod` 5 == 0 = putStrLn "Buzz" | |
| otherwise = return () | |
aToI :: String -> Int | |
aToI = read | |
main :: IO () | |
main = do | |
n <- getArgs >>= return . aToI . head | |
forM_ [1..n] printFizzBuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment