Created
October 29, 2014 22:49
-
-
Save purcell/f02794a2f17ee41bcae3 to your computer and use it in GitHub Desktop.
fizzbuzz
This file contains 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 FizzBuzz = Fizz | Buzz | FizzBuzz deriving Show | |
fizzbuzz :: Integral a => a -> Either FizzBuzz a | |
fizzbuzz n = case (n `rem` 3, n `rem` 5) of | |
(0, 0) -> Left FizzBuzz | |
(0, _) -> Left Fizz | |
(_, 0) -> Left Buzz | |
_ -> Right n | |
outputs :: [String] | |
outputs = map (either show show . fizzbuzz) [1..50] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment