This is a continuation to my previous post.
I'm creating a FizzBuzz function that allows 3 parameters to be entered. However, this isn't just the standard FizzBuzz program. This one allows for 2 divisors while implementing an upper range. So if div1 is divisible print "Fizz", if div2 is divisible print "buzz", and if div1 and div2 are divisible print "FizzBuzz", else print the number/integer.
I found different tutorials showing how to do the regular FizzBuzz in Haskell and modified it to be able to do as explained above.
Right now I'm getting an error and I'm not sure how to properly do this in Haskell.
fizzbuzz' :: [(Integer, String)] -> Integer -> String
fizzbuzz' ss n = foldl (\str (num, subst) -> if n `mod` num == 0 then str ++ subst else str ++ "") "" ss
fizzbuzz :: [(Integer, String)] -> Integer -> String
fizzbuzz ss n = if null str then show n else str
where str = fizzbuzz' ss n
fb :: Integer -> Integer -> Integer -> Integer
fb x y z = mapM_ putStrLn $ map (fizzbuzz [(x, "fizz"), (y, "buzz")]) [0..z]
The error I'm getting is:
Couldn't match expected type ‘Integer’ with actual type ‘IO ()’
In the expression:
mapM_ putStrLn $ map (fizzbuzz [(x, "fizz"), (y, "buzz")]) [0 .. z]
In an equation for ‘fb’:
fb x y z
= mapM_ putStrLn
$ map (fizzbuzz [(x, "fizz"), (y, "buzz")]) [0 .. z]
Failed, modules loaded: none.
Any ideas?
fbshould return? Why would you think that returns anInteger?