Reputation: 8116
Well, sorry for the bad title.
Consider the following function:
let inline getName arg =
( ^a : (member Name : string) arg)
I know what it does, but I know that only because I copy pasted it.
It says: given an arg
return the name
member of arg
.
However I don't get the first part ^a
, nor to I get the : (member Name : string)
.
All I know is that the last arg
is applying the value of arg
of the ^a : (member Name : string)
function.
Upvotes: 3
Views: 124
Reputation: 3697
The ^
is used to specify that the type parameter is statically resolved, this means that the type will be resolved at compile time, not at run time.
The second part is a generic constraint that specifies that the type must have a member called Name
with the given signature, in this case a string property. The syntax you show is how to actually call the member and the compiler is inferring the generic constraint on the function, but you could also specify the constraint explicitly, although there is no need.
let inline getName (arg : ^a when ^a : (member Name : string)) =
( ^a : (member Name : string) arg)
Upvotes: 9