I understand the tick to signify a generic parameter, as in:
Seq.append : seq<'T> -> seq<'T> -> seq<'T>
but what does the caret signify, as in:
Seq.average : seq<^T> -> ^T
A sign is composed of both a material form and a mental concept. The signifier is the material form, i.e., something that can be heard, seen, smelled, touched or tasted, whereas the signified is the mental concept associated with it. This the key difference between signifier and signified.
Ferdinand de Saussure, the other founder of semiotics saw signs as the basic unit of meaning and he defined two parts of signs. Signifier — The form of a sign. The form might be a sound, a word, a photograph, a facial expression, a painting of a pipe, etc. Signified — The concept or object that’s represented.
According to Saussure theory of signs, signifier and signified make up of signs. A sign is composed of both a material form and a mental concept. The signifier is the material form, i.e., something that can be heard, seen, smelled, touched or tasted, whereas the signified is the mental concept associated with it.
Peirce said the form a sign takes, it’s signifier, can be classified as one of three types an icon, an index, or a symbol. An Icon has a physical resemblance to the signified, the thing being represented. A photograph is a good example as it certainly resembles whatever it depicts. An Index shows evidence of what’s being represented.
The caret indicates that the type parameter must be statically resolved, usually because there are particular constraints on the type that must be satisfied and which can't be expressed in normal .NET metadata. For instance, you can't call Seq.average "test"
even though "test"
is a seq<char>
, because char
s don't support the necessary arithmetic operations.
These statically resolved type variables only arise from inline
defintions, and when such a function is used, its body is inlined so that the compiler can insert the correct type-specific instructions.
The detailed signature is:
Seq.average : seq<^T> -> ^T (requires ^T with static member (+) and ^T with static member DivideByInt and ^T with static member Zero)
Unlike Seq.append
, Seq.average needs some more constraints on type of elements. Particularly:
_ DivideByInt (s1 + s2 + ... + sn) n where n <> 0
Seq.average {s1; s2;...; sn} = /
\_ ^T.Zero where n = 0
As you can see, both (+)
, DivideByInt
and Zero
are required in order that Seq.average<^T>
makes sense.
Useful information about generics could be found hereMSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With