Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created October 10, 2012 01:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonymorris/3862632 to your computer and use it in GitHub Desktop.
Save tonymorris/3862632 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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