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?
- what ^ (circumflex) before t do?
- what "t" mean? generic type?
- what double -> do?
- what requires statements do?
i hope isn't cover in 1 answer.
- this indicates
t
statically resolved type parameter opposed normal generic type parameter (see 4 below). - yes.
->
type constructor functions , right associative, part equivalent^t -> (int -> ^t)
. in other words, if pass argument of type^t
function, you'll functionint
^t
.pown 2
function 2x power hasn't been passed yet. ,pown 2 8
same(pown 2) 8
: it's 28.- at point of invocation, whatever concrete type substituted
^t
must statically known meet these requirements. can callpown 2 8
(becauseint
supports these operations), notpown "test" 8
(becausestring
doesn't).
Comments
Post a Comment