Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active May 23, 2016 18:42
Show Gist options
  • Select an option

  • Save cobalamin/37726e3539b1a56cee30793fd9f0e6a3 to your computer and use it in GitHub Desktop.

Select an option

Save cobalamin/37726e3539b1a56cee30793fd9f0e6a3 to your computer and use it in GitHub Desktop.
Yet Another Unnecessary FizzBuzz in Haskell
module RidiculousFizzBuzz where
divBy :: Int -> Int -> Bool
divBy d x = x `mod` d == 0
fizzIt :: Int -> (Int, Bool, Bool)
fizzIt = (,,) <$> id <*> divBy 3 <*> divBy 5
fizzString :: (Int, Bool, Bool) -> String
fizzString (x, False, False) = show x
fizzString (_, True, False) = "Fizz"
fizzString (_, False, True) = "Buzz"
fizzString (_, True, True) = "FizzBuzz"
main :: IO ()
main = mapM_ (putStrLn . fizzString . fizzIt) [1..100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment