我正在尝试将内容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]
我怎样才能做到这一点?