Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the generic signifier ' and the symbol ^ In F# method signatures

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
like image 861
Joshua Belden Avatar asked Jun 28 '12 17:06

Joshua Belden


People also ask

What is the difference between a sign and a signifier?

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.

What is a signifier in semiotics?

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.

What is signifier and signified according to Saussure?

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.

What are the three types of signifiers?

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.


2 Answers

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 chars 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.

like image 172
kvb Avatar answered Sep 28 '22 16:09

kvb


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.

like image 21
pad Avatar answered Sep 28 '22 14:09

pad