Skip to content

Instantly share code, notes, and snippets.

@pb10005
Last active January 15, 2018 09:35
Show Gist options
  • Save pb10005/3457c4e08f6eea20f33dfb5662dcb04f to your computer and use it in GitHub Desktop.
Save pb10005/3457c4e08f6eea20f33dfb5662dcb04f to your computer and use it in GitHub Desktop.
fizzbuzz:: [Int] -> String
fizzbuzz xs = f xs ""
where
f [] s = s
f (y:ys) s = f ys (s++show(fizzbuzzfunc y)++footer)
fizzbuzzfunc x = header x ++ fizz x ++ buzz x
header x = show(x) ++ ": "
fizz x | mod x 3 == 0 = "fizz"
| otherwise = ""
buzz x | mod x 5 == 0 = "buzz"
| otherwise = ""
footer = "\n"
test:: [String]->IO()
test [] = putStrLn ""
test (x:xs) = putStrLn(x)>>= \_ ->
test(xs)
main = do
putStrLn "fizzbuzz in Haskell"
putStr $ fizzbuzz [1..30]
test ["a","b","c"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment