19 lines
534 B
Haskell
19 lines
534 B
Haskell
import Data.Maybe
|
|
|
|
maybeRead :: Read a => String -> Maybe a
|
|
maybeRead s = case reads s of
|
|
[(x,"")] -> Just x
|
|
_ -> Nothing
|
|
|
|
getListFromString :: String -> Maybe [Integer]
|
|
getListFromString str = maybeRead $ "[" ++ str ++ "]"
|
|
|
|
main :: IO ()
|
|
main = do
|
|
putStrLn "Enter a list of numbers (separated by comma):"
|
|
input <- getLine
|
|
let maybeList = getListFromString input in
|
|
case maybeList of
|
|
Just l -> print (sum l)
|
|
Nothing -> putStrLn "Bad format. Good Bye."
|