Commit eaccd9ac authored by Martin Janů's avatar Martin Janů
Browse files

Honor cmdline argument outside Int range

parent db5addc9
......@@ -30,17 +30,17 @@ say :: Either String Integer -> IO ()
say (Right x) = print x
say (Left x) = putStrLn x
sayNum :: Maybe Int -> IO ()
sayNum :: Maybe Integer -> IO ()
sayNum Nothing = say `foldMap` fizzbuzz
sayNum (Just n) = say `foldMap` (take n fizzbuzz)
sayNum (Just n) = (say.fizzeval) `foldMap` [1 .. n]
parseArgs :: [String] -> IO (Maybe Int)
parseArgs :: [String] -> IO (Maybe Integer)
parseArgs args =
if null args then pure Nothing else pure int
where int = if null parsed || (not $ null $ snd $ head parsed)
then Nothing
else Just $ fst $ head parsed
where parsed = reads $ head args :: [(Int, String)]
where parsed = reads $ head args :: [(Integer, String)]
main :: IO ()
main = getArgs >>= parseArgs >>= sayNum
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment