I've finished writing a Haskell program but I have troubles with the I/O and Main parts of it. I want to read input of the following format:
10 3
1 4 8
The first and second numbers are Ints, and the numbers of the second line should be made into an integer list, [Int]. The length of the list is equal to the second number on the first line.
I have the following code to read one Int at a time, however, it can only get it to work for the first line of input.
getInt :: IO Int
getInt = do
l <- getLine
return (read l)
What am I doing wrong?
wordsfunction - something likemap read . wordsshould work for you"10 3"- I would have expected this to give you an no parse errormap read . wordsI talked about - you can patternmatch as well if you like:[x, y] <- map read . words <$> getLineshould do the trick here for the first line - you get the second (in a list) by justnumbers <- map read . words <$> getLine(all in adoblock of course!)