Question

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

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

I can define the cross function and it compiles:

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

Unfortunately I'm not able to use it and have following error:

let res = cross a b
                 ^

The member or object constructor Cross takes 2 argument(s) but is here given 1. The required signature is static member Vector3.Cross : a:Vector3 * b:Vector3 -> Vector3

Is it even possible at all? Thanks for helping!

Was it helpful?

Solution

You've over-parenthesized your static member signature. Try this instead:

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

Given your definition, F# was looking for a member Cross which takes a single argument of tuple type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top