// F# Brute force:
let closest_pairs (xys: Point []) =
let n = xys.Length
seq { for i in 0..n-2 do
for j in i+1..n-1 do
yield xys.[i], xys.[j] }
|> Seq.minBy (fun 开发者_开发知识库(p0, p1) -> (p1 - p0).LengthSquared)
closest_pairs [|Point(0.0, 0.0); Point(1.0, 0.0); Point (2.0, 2.0)|]
Type constraint mismatch. The type Point
is not compatible with type Size The type 'Point' is not compatible with the type 'Size'Also Type issues with int v float
F# 2.0, .NET 4, VS 2010
You just need to have defined an appropriate Point
type first. Perhaps something like this:
type Point(x:float, y) =
member p.x = x
member p.y = y
member p.LengthSquared = x * x + y * y
static member (-)(p1:Point, p2:Point) = Point(p1.x-p2.x, p1.y-p2.y)
精彩评论