haskell - Haskell 不断给我类型错误
问题描述
不知道我做错了什么
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)]
推荐阅读
- javascript - 快捷键不起作用 ctrl + shift + numpad1
- c++ - 使用友元函数重载的 C++ 运算符。尝试添加多个对象失败
- javascript - 使用 lodash 对对象进行分组
- xamarin.forms - Microsoft Azure 存储数据移动库以及 xamarin 表单
- ios - 回到 UIViewController 不会触发 segue
- c# - 我可以帮助 C# 编译器推断这种类型吗?
- c - 如何在 CLion 中设置断点条件
- javascript - 更改 js 函数参数的引用
- sql - 如何不重复使用 SQL where 子句
- android - 如何将图像添加到 ProgressDialog?