无法匹配预期类型 - Haskell
我是 Haskell 的新手,仍然不能完全弄清楚这些类型问题。我收到以下函数的错误:
computeTriUp :: Point -> Float -> [Point]
computeTriUp center r = [(x + r*cos(pi/2.0), y+r*sin(pi/2.0)), (x+r*cos(5.0*pi/4.0), y+r*sin(5.0*pi/4.0)), (x+r*cos(7.0*pi/4.0), y+r*sin(7.0*pi/4.0))]
where x = fst center
y = snd center
我的错误是:
Couldn't match expected type `Int' with actual type `Float'
In the first argument of `(*)', namely `r'
In the second argument of `(+)', namely `r * cos (pi / 2.0)'
In the expression: x + r * cos (pi / 2.0)
有什么想法吗? 谢谢!
I'm new to Haskell and still can't quite figure out these type issues. I'm getting errors for the following function:
computeTriUp :: Point -> Float -> [Point]
computeTriUp center r = [(x + r*cos(pi/2.0), y+r*sin(pi/2.0)), (x+r*cos(5.0*pi/4.0), y+r*sin(5.0*pi/4.0)), (x+r*cos(7.0*pi/4.0), y+r*sin(7.0*pi/4.0))]
where x = fst center
y = snd center
My error is:
Couldn't match expected type `Int' with actual type `Float'
In the first argument of `(*)', namely `r'
In the second argument of `(+)', namely `r * cos (pi / 2.0)'
In the expression: x + r * cos (pi / 2.0)
Any ideas?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 Point 是一对 Int,您可能想要更改 x 和 y 的定义以将它们转换为 Floats...
Assuming Point is a pair of Ints, you probably want to change the definitions of x and y to convert them to Floats...