可以匹配预期的类型‘ int’使用实际类型(int,int,int)

发布于 2025-02-04 18:08:52 字数 378 浏览 2 评论 0原文

我有一个动态的txt文件示例(1,1,1),我试图从文件中读取它们 将它们传递到问题功能。

函数问题:: 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)'

i have a dynamic txt file example (1,1,1), im trying to read them from file
to pass them to problem function.

function 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))

Couldn't match expected type ‘Int’
with actual type ‘(Int, Int, Int)’

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2025-02-11 18:08:52

您需要提取三个int值,以便将它们单独传递到问题

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

相反,您可以定义uncurry3函数以适应问题与元组一起使用。

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

print (show ((uncurry3 problem) value))

You need to extract the three Int values in order to pass them individually to problem.

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

Conversely, you could define an uncurry3 function to adapt problem to work with a tuple.

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

print (show ((uncurry3 problem) value))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文