ฉันกำลังเขียนโปรแกรมนั้นจะได้ค่ารายชื่อของ k ทีใกลทีสุดหางออกไปเพื่อนบ้านอยู่ระยะห่างคำสั่งจากเมตริก the imperial system d ที่จุดพีในช่องรายการ ps ของกระจุย ทุกคนควรจะกลับมาเป็นเพื่อนบ้านที่เหมาะสมหากอยู่ในรายการ ps เป็นน้อยกว่าเคองธาตุหลัก-แล้วอีก แล้วก็สองอย่างเท่าเทียมกันใกล้จุดที่ p ควรจะกลับมาจากพวกเขาเริ่มลำดับในรายการ ps
import Data.List
type Point a = (a,a)
type Metric a = (Point a) -> (Point a) -> Double
nearPoints :: Int -> Metric a -> Point a -> [Point a] -> [Point a]
nearPoints k d p [] = []
nearPoints k d p ps = take k (sortOn (pointsDistCalc p) ps)
pointsDistCalc :: Metric Double
pointsDistCalc (t1,t1) (t2,t2) = sqrt(((t1-t2)^2)+((t1-t2)^2))
นี่คือข้อความผิดพลาด
* Couldn't match type `a' with `Double'
`a' is a rigid type variable bound by
the type signature for:
nearPoints :: forall a.
Int -> Metric a -> Point a -> [Point a] -> [Point a]
Expected type: Point Double
Actual type: Point a
* In the first argument of `pointsDistCalc', namely `p'
In the first argument of `sortOn', namely `(pointsDistCalc p)'
In the second argument of `take', namely
`(sortOn (pointsDistCalc p) ps)'
* Relevant bindings include
ps :: [Point a]
p :: Point a
d :: Metric a
nearPoints :: Int -> Metric a -> Point a -> [Point a] -> [Point a]
11 | nearPoints k d p ps = take k (sortOn (pointsDistCalc p) ps)
ได้โปรดใครก็ได้ช่วยฉันกับเรื่องนี้