-
-
Save philandstuff/ef740b11470a17bf9bb5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 FizzBuzz where | |
import Data.Maybe | |
data FizzBuzz = Fizz | Buzz deriving Show | |
whenDivisible :: Integral a => a -> b -> a -> Maybe b | |
whenDivisible d x n = if n `rem` d == 0 then Just x else Nothing | |
fizzbuzz :: (Show a, Integral a) => a -> String | |
fizzbuzz n = if null tags then show n else concatMap show tags | |
where tags = catMaybes [fizz n, buzz n] | |
fizz = whenDivisible 3 Fizz | |
buzz = whenDivisible 5 Buzz | |
main = mapM_ (putStrLn . fizzbuzz) [1..50] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment