Loading fizzbuzz.hs +4 −4 Original line number Diff line number Diff line Loading @@ -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 Loading
fizzbuzz.hs +4 −4 Original line number Diff line number Diff line Loading @@ -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