Scott Nimrod
Scott Nimrod

Reputation: 11595

What does "^" mean when it's in front of a type?

What does "^" mean when it's in front of a type?

Example:

int : ^T -> int

string : ^T -> string

Upvotes: 3

Views: 1128

Answers (1)

Random Dev
Random Dev

Reputation: 52270

this indicates an Statically Resolved Type Parameter

from MSDN:

A statically resolved type parameter is a type parameter that is replaced with an actual type at compile time instead of at run time. They are preceded by a caret (^) symbol.

so it's very similar to 'T but you can use it to give member constraints and the compiler will resolve them at compile-time (obviously) - usually you are just using inline and the type-inference will work it out for you - but there are some quite advanced tricks (for example FsControl) out there using this (not often used) feature

example

let inline add a b = a + b

val inline add :
  a: ^a -> b: ^b ->  ^c
    when ( ^a or  ^b) : (static member ( + ) :  ^a *  ^b ->  ^c)

will add such a constraint to indicate that this will work with all numeric types (it will add an member constraint to an static operator (+))

Upvotes: 8

Related Questions