不知道我做错了什么
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))
| ^^
Run Code Online (Sandbox Code Playgroud)
Location, Int, [place] 都被发送到一个返回 [(Name, Float)] 的函数,该函数又被发送到一个返回 (Name,Float) 的函数我不知道为什么这个程序不能运行. 为什么不能匹配类型
编辑:重写函数后,我设法正确地写下来,没有匹配错误
你的类型不对:
rtnClosestDryPlace :: (Location -> Int -> [Place] -> [(Name,Float)]) -> (Name,Float)
Run Code Online (Sandbox Code Playgroud)
意味着这rtnClosestDryPlace
是一个函数,其输入参数具有类型
(Location -> Int -> [Place] -> [(Name,Float)])
Run Code Online (Sandbox Code Playgroud)
并且其输出参数具有类型
(Name,Float)
Run Code Online (Sandbox Code Playgroud)
因此,该类型承诺,给定 3 个参数的函数,下面的代码能够返回一对。那不是你想要的。
我猜你真的想要类似的东西
rtnClosestDryPlace :: Location -> Int -> [Place] -> [(Name,Float)]
Run Code Online (Sandbox Code Playgroud)