Skip to content

Instantly share code, notes, and snippets.

@kputnam
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save kputnam/f235794716a9dcbeaf85 to your computer and use it in GitHub Desktop.

Select an option

Save kputnam/f235794716a9dcbeaf85 to your computer and use it in GitHub Desktop.
{-# LANGUAGE MonadComprehensions #-}
import Data.Maybe
import Data.Monoid
fizzBuzz :: [(Int, String)] -> Int -> String
fizzBuzz ds n = fromMaybe (show n) $ mconcat [[s | d `divides` n] | (d,s) <- ds]
where x `divides` y = y `mod` x == 0
main :: IO ()
main = mapM_ (putStrLn . fizzBuzz ds) [1..99]
where ds = [(3, "fizz"), (5, "buzz")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment