Skip to content

Instantly share code, notes, and snippets.

@P7h
Created February 4, 2017 15:50
Show Gist options
  • Save P7h/1a79b21aa1a9a1b17701b99c53b51c84 to your computer and use it in GitHub Desktop.
Save P7h/1a79b21aa1a9a1b17701b99c53b51c84 to your computer and use it in GitHub Desktop.
FizzBuzz in Haskell
-- FizzBuzz in Haskell
fizzbuzz :: Int -> String
fizzbuzz n = if fb /= ""
then fb
else show n
where fb = fizz n ++ buzz n
fizz:: Int -> String
fizz n | n `mod` 3 == 0 = "Fizz"
| otherwise = ""
buzz:: Int -> String
buzz n | n `mod` 5 == 0 = "Buzz"
| otherwise = ""
main = do
mapM_ (putStrLn) [fizzbuzz x | x <- [1..100]]
-- ghc fizzbuzz.hs
-- fizzbuzz.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment