As part of a programming challenge, I need to read, from stdin, a sequence of space-separated integers (on a single line), and print the sum of those integers to stdout
I would venture to guess that a big part of your problem is actually words
. When you map read . words
, what you're actually doing is this:
This is a fairly ridiculous way to proceed. I believe you can even do better using something horrible like reads
, but it would make more sense to use something like ReadP. You can also try fancier sorts of things like stream-based parsing; I don't know if that will help much or not.