相关疑难解决方法(0)

从haskell中的stdin读取输入并转换为整数列表

以下代码有什么问题?我只是想在文件中以下列格式转换输入:n - 测试用例的数量// n个数字n1 n2(通过stdin读取)到整数列表并显示它?

socks :: Int -> Int
socks x = x + 1
strToInt = read :: String -> Int
strLToIntL :: [String] -> [Int]
strLToIntL xs = map (strToInt) xs
main = do
    n <- readLn :: IO Int
    mapM_ putStrLn $ map show $ strLToIntL $ fmap (take n . lines) getContents
Run Code Online (Sandbox Code Playgroud)

我运行它时收到编译错误:

Couldn't match expected type `Char' with actual type `[Char]'
Expected type: String -> [Char]
  Actual type: String -> [String]
In the second …
Run Code Online (Sandbox Code Playgroud)

haskell

5
推荐指数
1
解决办法
5253
查看次数

标签 统计

haskell ×1