Reputation: 176
Don't know what I'm doing wrong
type Name = String
type Location = (Float,Float)
type RainfallFigures = [Int]
type Place = (Name,Location,RainfallFigures)
rtnClosestDryPlace :: (Location -> Int -> [Place] -> [(Name,Float)]) -> (Name,Float)
rtnClosestDryPlace p1 n ((a,p2,c):xs) = rtnLowestDistance (distanceList p1 (rtnFullDryPlaces ((a,p2,c):xs) n))
Couldn't match expected type ‘(Name, Float)’
with actual type ‘Int
-> [(Name, Location, RainfallFigures)] -> (Name, Float)’
• The equation(s) for ‘rtnClosestDryPlace’ have three arguments,
but its type ‘(Location -> Int -> [Place] -> [(Name, Float)])
-> (Name, Float)’
has only one
rtnClosestDryPlace p1 n ((a,p2,c):xs) = rtnLowestDistance (distanceList p1 (rtnFullDryPlaces ((a,p2,c):xs) n))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
template.hs:90:73: error:
• Couldn't match expected type ‘(Float, Float)’
with actual type ‘Location -> Int -> [Place] -> [(Name, Float)]’
• Probable cause: ‘p1’ is applied to too few arguments
In the first argument of ‘distanceList’, namely ‘p1’
In the first argument of ‘rtnLowestDistance’, namely
‘(distanceList p1 (rtnFullDryPlaces ((a, p2, c) : xs) n))’
In the expression:
rtnLowestDistance
(distanceList p1 (rtnFullDryPlaces ((a, p2, c) : xs) n))
|
90 | rtnClosestDryPlace p1 n ((a,p2,c):xs) = rtnLowestDistance (distanceList p1 (rtnFullDryPlaces ((a,p2,c):xs) n))
| ^^
Location, Int, [place] all get sent to a function which returns [(Name, Float)], which in turn gets sent to a function which returns (Name,Float) I don't know why this program can't run. Why can it not match the types
Edit: After rewriting the function I’ve managed to correctly write it down with no matching errors
Upvotes: 1
Views: 70
Reputation: 116139
Your type is wrong:
rtnClosestDryPlace :: (Location -> Int -> [Place] -> [(Name,Float)]) -> (Name,Float)
means that rtnClosestDryPlace
is a function whose input argument has type
(Location -> Int -> [Place] -> [(Name,Float)])
and whose output argument has type
(Name,Float)
So, that type promises that, given a 3-arguments function, the code below is able to return a pair. That's not what you want.
I guess you actually want something like
rtnClosestDryPlace :: Location -> Int -> [Place] -> [(Name,Float)]
Upvotes: 4