haskell 无法 将 预期 类型 ' Int ' 与 实际 类型 ( Int , Int , Int ) 匹配

yeotifhr  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(150)

我有一个动态的txt文件的例子(1,1,1),我试图从文件中读取它们,并将它们传递给问题函数。
函数problem :: Int->Int->Int->[Int]

args <- getArgs
   contents <- readFile (head args)
   let value = read contents::(Int,Int,Int)

   //print(show(problem 1 1 1))
   print(show(problem value))

无法将预期类型'Int'与实际类型'(Int,Int,Int)'相符

tkclm6bt

tkclm6bt1#

您需要提取三个Int值,以便将它们分别传递给problem

let (a, b, c) = read contents :: (Int, Int, Int)
print (show (problem a b c))

相反地,您可以定义uncurry3函数来调整problem以使用元组。

uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d)
uncurry3 f = \(x,y,z) -> f x y z

print (show ((uncurry3 problem) value))

相关问题