-- Sum the integers in the standard input stream module Main where main :: IO() main = interact (addln . show . sum . (map readInt) . words) -- Specialize 'read' from the Haskell prologue for integers. -- Without the type information, 'read' won't know what type -- is desired and 'sum' is happy with a whole class of numbers. readInt :: String -> Int readInt = read {- (++) :: [a] -> [a] -> [a] ; sequence (list) concatentation -} addln :: String -> String addln s = s ++ "\n" -- same as the section: (++ "\n") -- ------------For GNU Emacs ------------ -- Local Variables: -- compile-command: "ghc -Wall sum.hs" -- End: