Q:

Haskell print map over array

I'm practicing with a problem that gives text input on stdin and wants output on stdout.
They give an integer T in the first line that I read, and then T lines follow. For the T following lines I have a function that takes an integer and returns an integer that I must print. So my output should be T lines.
I'm stuck at this point:
main = do
    strcases <- getLine
    map (calculate) [1..(read strcases)]

calculate _ = do
    strp <- getLine
    print $ addone (read strp)

addone x = x+1

Of course this doesn't work at the moment. Can you show how to print the T lines of output?

A:

You can use readLn, which combines getLine and read, and replicateM_ from Control.Monad to repeat an IO action (or any monad) a given number of times:
import Control.Monad

main :: IO ()
main = do
    n <- readLn
    replicateM_ n calculate

calculate :: IO ()
calculate = do
    x <- readLn
    print $ addone x

addone :: Int -> Int
addone x = x+1

Note, the underscore suffix on replicateM_ indicates that the return value of each executed action be discarded.  The alternative function without the underscore suffix will return a list containing the return value of each executed action, which we do not want in this case.

