Skip to content

Instantly share code, notes, and snippets.

@roehst
Created January 29, 2018 21:36
Show Gist options
  • Save roehst/2b83bef7d6941481463d98095657a2d2 to your computer and use it in GitHub Desktop.
Save roehst/2b83bef7d6941481463d98095657a2d2 to your computer and use it in GitHub Desktop.
module Main where
fizzBuzz :: Int -> IO ()
fizzBuzz n | n `mod` 5 == 0 && n `mod` 3 == 0 = putStrLn "Fizz Buzz"
| n `mod` 5 == 0 = putStrLn "Buzz"
| n `mod` 3 == 0 = putStrLn "Buzz"
| otherwise = return ()
runManyActions [] = return []
runManyActions (x:xs) = do
y <- x
ys <- runManyActions xs
return (y:ys)
main :: IO ()
main = do
let actions = runManyActions $ map fizzBuzz [1..50]
results <- actions
return ()
module Main where
fizzBuzz :: Int -> IO ()
fizzBuzz n | n `mod` 5 == 0 && n `mod` 3 == 0 = putStrLn "Fizz Buzz"
| n `mod` 5 == 0 = putStrLn "Buzz"
| n `mod` 3 == 0 = putStrLn "Buzz"
| otherwise = return ()
main :: IO ()
main = do
let ns = [1..100]
runFizzBuzz ns
runFizzBuzz :: [Int] -> IO ()
runFizzBuzz [] = return ()
runFizzBuzz (x:xs) = do
fizzBuzz x
runFizzBuzz xs
module Main where
fizzBuzz :: Int -> Maybe String
fizzBuzz n | n `mod` 5 == 0 && n `mod` 3 == 0 = Just "Fizz Buzz"
| n `mod` 5 == 0 = Just "Buzz"
| n `mod` 3 == 0 = Just "Fizz"
| otherwise = Nothing
main :: IO ()
main = do
let ns = [1..100]
let messages = dropMaybes $ map fizzBuzz ns
mapM putStrLn messages
return ()
dropMaybes [] = []
dropMaybes (x:xs) =
case x of
Nothing -> dropMaybes xs
Just y -> y : dropMaybes xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment