Understanding F# documentation function signatures -


i learning f# free online resource. since curious , try apply learned stuff in small excercises, find myself consulting msdn f# documentation quite often.

but documentation seems cryptic me. take documentation page pown function example. usage pretty straight forward, don't understand functions signature:

// signature: pown : ^t -> int -> ^t (requires ^t static member 1 , ^t static member op_multiply , ^t static member (/)) 

can explain me, following things about?

  1. what ^ (circumflex) before t do?
  2. what "t" mean? generic type?
  3. what double -> do?
  4. what requires statements do?

i hope isn't cover in 1 answer.

  1. this indicates t statically resolved type parameter opposed normal generic type parameter (see 4 below).
  2. yes.
  3. -> type constructor functions , right associative, part equivalent ^t -> (int -> ^t). in other words, if pass argument of type ^t function, you'll function int ^t. pown 2 function 2x power hasn't been passed yet. , pown 2 8 same (pown 2) 8: it's 28.
  4. at point of invocation, whatever concrete type substituted ^t must statically known meet these requirements. can call pown 2 8 (because int supports these operations), not pown "test" 8 (because string doesn't).

Comments