Multiple restriction of arity static type

Let's say I have a bunch of vector types (a la XNA), and some of them have a static member Cross:

type Vector3 =
  ...
  static member Cross (a : Vector3, b : Vector3) = new Vector3(...)

I can define a function Crossand it compiles:

let inline cross (x : ^T) (y : ^T) = (^T : (static member Cross : (^T * ^T) -> ^T) ((x,y)))

Unfortunately, I cannot use it and have the following error:

let res = cross a b
                 ^

The constructor of a Cross element or object takes 2 arguments, but here 1. The required signature is a static member of Vector3.Cross: a: Vector3 * b: Vector3 → Vector3

Is this even possible? Thanks for the help!

+5
source share
1 answer

You have indicated your static member signature in brackets. Try instead:

let inline cross (x : ^T) (y : ^T) = 
  (^T : (static member Cross : ^T * ^T -> ^T) (x,y))

, F # Cross, .

+5

All Articles