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'
不能正確解析
我不明白這一點。顯然,特定於類型的運算符不會優先於泛型運算符,這會挫敗我的直覺。做這項工作有什麼竅門?