let inline (=~) a b = abs (single a - single b) <= 0.001f
type Vector =
{ x : single; y : single; z : single }
static member (=~) (v1, v2) = (v1.x =~ v2.x) && (v1.y =~ v2.y) && (v1.z =~ v2.z)
let v1, v2 =
{ x = 0.1f; y = single Math.PI; z = 0.f },
{ x = 0.1f; y = 3.14159f; z = 0.0001f }
v1 =~ v2
编译F#运营商抱怨:The type 'Vector' does not support a conversion to the type 'single'
不能正确解析
我不明白这一点。显然,特定于类型的运算符不会优先于泛型运算符,这会挫败我的直觉。做这项工作有什么窍门?