Attempting to implement fizzBuzz with some command line using optparse-applicative.
import Options.Applicative
data Args = Args { firstDivisor :: Int,
secondDivisor :: Int,
upperBound :: Int }
fizzBuzz :: Args -> IO ()
fizzBuzz opts i
| i `mod` firstDivisor opts == 0 && i `mod` secondDivisor opts == 0 = "fizzBuzz"
| i `mod` firstDivisor opts == 0 = "fizz"
| i `mod` secondDivisor opts == 0 = "buzz"
| otherwise = show i
main :: IO ()
main = print fizzBuzz
I have it set up to take in three command line arguments; two divisors(in fizzBuzz usually 3 and 5), and the third being the upper limit(usually 100), but when I go to compile I get an error saying:
Couldn't match expected type ‘Int -> [Char]’
with actual type ‘IO ()’
The equation(s) for ‘fizzBuzz’ have two arguments,
but its type ‘Args -> IO ()’ has only one
My main goal is to just print out the fizzBuzz series with the three command line args. From what I understand, it isn't liking that I supplied fizzBuzz with an extra parameter. Trying to understand why 'i' wouldn't work here.
UPDATE:
This code I feel is closer, as it addresses the command line with getArgs
instead of optparse. Also added a list to run against fizzBuzz
.
import System.Environment
main :: IO ()
main = do
[s1,s2,s3] <- getArgs
print m
m = [ fizzBuzz i| i <-[1..s3]]
fizzBuzz i
| i `mod` s1 == 0 && s1 `mod` s2 == 0 = "fizzBuzz"
| i `mod` s1 == 0 = "fizz"
| i `mod` s2 == 0 = "buzz"
| otherwise = show i
So my problem is that I cannot access the s1 and s2 variables in order to get my fizzBuzz goin. How can I access those args outside of the scope of main? Maybe there is another function that can help?