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)]

给TA打赏
共{{data.count}}人
人已打赏
解决方案

Javascript:正确地将日期字符串转换为日期对象

2022-4-20 16:09:08

解决方案

WPF闪屏UI不更新

2022-4-20 17:08:52

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索