Skip to content

Instantly share code, notes, and snippets.

@dreum
Last active January 1, 2022 23:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dreum/0a2045f919d1336c6ffc8e0d70737781 to your computer and use it in GitHub Desktop.
Save dreum/0a2045f919d1336c6ffc8e0d70737781 to your computer and use it in GitHub Desktop.
import Data.Maybe
fizzBuzz n =
let
base divisor s =
if (n `mod` divisor) == 0
then Just s
else Nothing
maybeFizz = base 3 "Fizz"
maybeBuzz = base 5 "Buzz"
in fromMaybe (show n) (maybeFizz <> maybeBuzz)
main = mapM_ (putStrLn . fizzBuzz) [1..100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment