Last active
August 29, 2015 14:01
-
-
Save gatlin/623527079b12aca96eac to your computer and use it in GitHub Desktop.
Haskell FizzBuzz solution using monoids. I didn't write this but I wanted to separate it from its original article for didactic reasons.
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
{-# LANGUAGE MonadComprehensions #-} | |
-- From https://bmark.us/bmark/readable/060063d3dd0330 | |
import Data.Monoid ((<>)) | |
import Data.Maybe (fromMaybe) | |
import Control.Monad (mapM_) | |
fizzbuzz x = fromMaybe (show x) $ [ "fizz" | x `rem` 3 == 0 ] | |
<> [ "buzz" | x `rem` 5 == 0 ] | |
<> [ "bazz" | x `rem` 7 == 0 ] | |
main = mapM_ putStrLn [ fizzbuzz i | i <- [1..100] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment