Created
January 29, 2018 21:36
-
-
Save roehst/2b83bef7d6941481463d98095657a2d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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