Created
October 10, 2012 01:37
-
-
Save tonymorris/3862632 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 Main where | |
import Control.Applicative ((<*>)) | |
import Data.Semigroup ((<>)) -- http://hackage.haskell.org/package/semigroups | |
import Data.Maybe (fromMaybe, listToMaybe, maybe) | |
import System.Environment (getArgs) | |
import Data.Lens.Partial.Common(getorPL, headLens) -- http://hackage.haskell.org/package/data-lens | |
fizzbuzz :: | |
Integral a => | |
a | |
-> String | |
fizzbuzz = | |
let x .| True = Just x | |
_ .| False = Nothing | |
s ~> q = (s .|) . (0 ==) . (`rem` q) | |
in fromMaybe . show <*> | |
"fizz" ~> 3 <> | |
"buzz" ~> 5 <> | |
"bazz" ~> 7 | |
main :: | |
IO () | |
main = | |
do a <- getArgs | |
let z = fmap fizzbuzz [1..getorPL headLens 100 . fmap read $ a] | |
mapM_ putStrLn z | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't need import Data.Maybe(listToMaybe, maybe)