Skip to content

Instantly share code, notes, and snippets.

Created August 16, 2014 20:14
Show Gist options
  • Save anonymous/5eff1bb00d4ac7d558ad to your computer and use it in GitHub Desktop.
Save anonymous/5eff1bb00d4ac7d558ad to your computer and use it in GitHub Desktop.
Pretty FizzBuzz with types and stuff!
import Data.List
data FizzBuzz = Fizz | Buzz | FizzBuzz | Num Int
instance Show FizzBuzz where
show Fizz = "Fizz"
show Buzz = "Buzz"
show FizzBuzz = "FizzBuzz"
show (Num n) = show n
bzzr :: Int -> FizzBuzz
bzzr n | zeroMod 15 = FizzBuzz
| zeroMod 3 = Fizz
| zeroMod 5 = Buzz
| otherwise = Num n
where
zeroMod x = mod n x == 0
main :: IO ()
main = print $ intercalate ", " $ map (show . bzzr) [1..100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment