Прочитать n строк в [String]

Я пытаюсь прочитать nстрок содержимого в список строк. Я пробовал несколько вариантов кода ниже, но ничего не получалось.

main = do
  input <- getLine
  inputs <- mapM getLine [1..read input]
  print $ length input

Это выдает следующую ошибку:

Couldn't match expected type `a0 -> IO b0'
                with actual type `IO String'
    In the first argument of `mapM', namely `getLine'
    In a stmt of a 'do' block: inputs <- mapM getLine [1.. read input]
    In the expression:
      do { input <- getLine;
           inputs <- mapM getLine [1.. read input];
           print $ length input }

И

main = do
  input <- getLine
  let inputs = map getLine [1..read input]
  print $ length input

выдает

 Couldn't match expected type `a0 -> b0'
                with actual type `IO String'
    In the first argument of `map', namely `getLine'
    In the expression: map getLine [1.. read input]
    In an equation for `inputs': inputs = map getLine [1.. read input]

Как я могу это сделать?

10
задан user1349427 23 April 2012 в 18:06
поделиться