her.esy.fun/src/posts/0010-Haskell-Now/io_sum_safe.hs
Yann Esposito (Yogsototh) 250335f16b
progress
2019-12-26 12:45:11 +01:00

15 lines
391 B
Haskell

import Data.Maybe
import Text.Read (readMaybe)
getListFromString :: String -> Maybe [Integer]
getListFromString str = readMaybe $ "[" ++ str ++ "]"
main :: IO ()
main = do
putStrLn "Enter a list of numbers (separated by comma):"
input <- getLine
let maybeList = getListFromString input
case maybeList of
Just l -> print (sum l)
Nothing -> putStrLn "Bad format. Good Bye."