type Point = (Double, Double)
flipsOneY :: Point -> (Int, Int) -> Point
flipsOneY point (i, j) = ((fst point), ((fromIntegral j) - (snd point)))
changeY :: [Point] -> (Int, Int) -> [Point]
changeY xs (i, j) = map flipsOneY xs (i, j)
我有一个点(x,y)列表,我想改变Y坐标的值。当我尝试编译这个我收到这个错误:
Expr.hs:149:21:
Couldn't match expected type `(Int, Int) -> Point'
with actual type `[(Int, Int) -> Point]'
The function `map' is applied to three arguments,
but its type `(Point -> (Int, Int) -> Point)
-> [Point] -> [(Int, Int) -> Point]'
has only two
In the expression: map flipsOneY xs (i, j)
In an equation for `changeY':
changeY xs (i, j) = map flipsOneY xs (i, j)
我猜我没有正确使用地图。任何提示解决方案的提示都表示赞赏。 : - )
答案 0 :(得分:3)
type Point = (Double, Double)
flipsOneY :: Point -> (Int, Int) -> Point
flipsOneY point (i, j) = ((fst point), ((fromIntegral j) - (snd point)))
changeY :: [Point] -> (Int, Int) -> [Point]
changeY xs (i, j) = map flipsOneY xs (i, j)
map
需要2个参数,但你传递的是3个。
尝试在flipOnesY
调用周围加上括号,如下所示:
changeY :: [Point] -> (Int, Int) -> [Point]
changeY xs (i, j) = map (\ys -> flipsOneY ys (i, j)) xs
这也向您显示您对flipsOneY的参数顺序不是最佳的。