Reputation: 347
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)
I have a list of points (x, y) where i want to change the value of the Y coordinate. When i try to compile this i recieve this error:
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)
I am guessing i am not using map correctly. Any hint towards a solution is appreciated. :-)
Upvotes: 0
Views: 108
Reputation: 137997
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
takes 2 arguments but you are passing it three.
Try putting parenthesis around the flipOnesY
call, like so:
changeY :: [Point] -> (Int, Int) -> [Point]
changeY xs (i, j) = map (\ys -> flipsOneY ys (i, j)) xs
This also shows you that your argument order to flipsOneY is not optimal.
Upvotes: 3