Skip to content

Instantly share code, notes, and snippets.

@purcell
Created October 29, 2014 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purcell/f02794a2f17ee41bcae3 to your computer and use it in GitHub Desktop.
Save purcell/f02794a2f17ee41bcae3 to your computer and use it in GitHub Desktop.
fizzbuzz
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