Skip to content

Instantly share code, notes, and snippets.

@P7h P7h/FizzBuzz.hs
Created Feb 4, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.