Create a gist now

Instantly share code, notes, and snippets.

FizzBuzz
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
@tonymorris
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment