开发者

Couldn't match expected type - Haskell

开发者 https://www.devze.com 2023-04-10 04:30 出处:网络
I\'m new to Haskell and still can\'t quite figure out these type issues.I\'m getting e开发者_高级运维rrors for the following function:

I'm new to Haskell and still can't quite figure out these type issues. I'm getting e开发者_高级运维rrors 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!


Assuming Point is a pair of Ints, you probably want to change the definitions of x and y to convert them to Floats...

x = fromIntegral $ fst centre
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号