【发布时间】:2011-11-30 09:32:29
【问题描述】:
我是 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)
有什么想法吗? 谢谢!
【问题讨论】:
-
Point的定义是什么? -
另外,最好在
(x,y)上进行显式模式匹配,除非您打算稍后替换Point的定义,并且这样做可以最大限度地减少代码更改...
标签: haskell types floating-point int