不知道自己做错了什么?
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]都会被发送到一个函数,这个函数返回[(Name,Float)],而这个函数又会被发送到一个函数,这个函数返回(Name,Float)我不知道为什么这个程序不能运行。为什么它不能匹配类型
编辑:重写函数后,我已经设法正确地写下来了,而且没有匹配的错误。
你的类型是错误的。
rtnClosestDryPlace :: (Location -> Int -> [Place] -> [(Name,Float)]) -> (Name,Float)
意思是 rtnClosestDryPlace
是一个输入参数类型为
(Location -> Int -> [Place] -> [(Name,Float)])
而其输出参数类型为
(Name,Float)
所以,该类型承诺,给定一个3个参数的函数,下面的代码能够返回一对。这不是你想要的。
我猜你实际上想要的是像
rtnClosestDryPlace :: Location -> Int -> [Place] -> [(Name,Float)]