Last active
November 10, 2018 23:40
-
-
Save jjant/2fd35584cffb3276950e0e515622cb1b 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 | |
| data FizzResult | |
| = Val Int | |
| | Fizz | |
| | Buzz | |
| | FizzBuzz | |
| deriving (Show) | |
| divisibleBy :: Int -> Int -> Bool | |
| divisibleBy divisor x = x `mod` divisor == 0 | |
| fizzbuzz :: Int -> FizzResult | |
| fizzbuzz x = | |
| case (divisibleBy 3 x, divisibleBy 5 x) of | |
| (True, True) -> FizzBuzz | |
| (True, False) -> Fizz | |
| (False, True) -> Buzz | |
| (False, False) -> Val x | |
| -- Run fizzbuzz over every int from 1 to 100 and print the result. | |
| main :: IO () | |
| main = traverse (print . fizzbuzz) [1 .. 100] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment