public
Created

FizzBuzz

  • Download Gist
FizzBuzz.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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

Don't need import Data.Maybe(listToMaybe, maybe)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.