Dictionary: A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y   Z

Generic type variable

programming
(Also known as a “schematic type variable”). Different occurrences of a generic type variable in a type expression may be instantiated to different types. Thus, in the expression
let id x = x in (id True, id 1)
id’s type is (for all a: a -> a). The universal quantifier “for all a:” means that a is a generic type variable. For the two uses of id, a is instantiated to Bool and Int. Compare this with
let id x = x in let f g = (g True, g 1) in f id
This looks similar but f has no legal Hindley-Milner type. If we say
f :: (a -> b) -> (b, b)
this would permit g’s type to be any instance of (a -> b) rather than requiring it to be at least as general as (a -> b). Furthermore, it constrains both instances of g to have the same result type whereas they do not. The type variables a and b in the above are implicitly quantified at the top level:
f :: for all a: for all b: (a -> b) -> (b, b)
so instantiating them (removing the quantifiers) can only be done once, at the top level. To correctly describe the type of f requires that they be locally quantified:
f :: ((for all a: a) -> (for all b: b)) -> (c, d)
which means that each time g is applied, a and b may be instantiated differently. f’s actual argument must have a type at least as general as ((for all a: a) -> (for all b: b)), and may not be some less general instance of this type. Type variables c and d are still implicitly quantified at the top level and, now that g’s result type is a generic type variable, any types chosen for c and d are guaranteed to be instances of it.
This type for f does not express the fact that b only needs to be at least as general as the types c and d. For example, if c and d were both Bool then any function of type (for all a: a -> Bool) would be a suitable argument to f but it would not match the above type for f.

Tagged:

• Generis

[ah-li-ey-nee ge-ne-ris; English ey-lahy-ee-nahy jen-er-is, ey-lee-] /ˌɑ lɪˈeɪ ni ˈgɛ nɛ rɪs; English ˌeɪ laɪˈi naɪ ˈdʒɛn ər ɪs, ˌeɪ li-/ adjective, Latin. 1. of another kind. [ah-mee-koo s hoo-mah-nee ge-ne-ris; English uh-mahy-kuh s hyoo-mey-nahy jen-uh-ris, uh-mee-kuh s hyoo-mey-nee] /ɑˈmi kʊs huˈmɑ ni ˈgɛ nɛ rɪs; English əˈmaɪ kəs hyuˈmeɪ naɪ ˈdʒɛn ə rɪs, əˈmi […]

• Generosity

[jen-uh-ros-i-tee] /ˌdʒɛn əˈrɒs ɪ ti/ noun, plural generosities. 1. readiness or liberality in giving. 2. freedom from meanness or smallness of mind or character. 3. a act: We thanked him for his many generosities. 4. largeness or fullness; amplitude. /ˌdʒɛnəˈrɒsɪtɪ/ noun (pl) -ties 1. willingness and liberality in giving away one’s money, time, etc; magnanimity […]

• Generous

[jen-er-uh s] /ˈdʒɛn ər əs/ adjective 1. liberal in giving or sharing; unselfish: a generous patron of the arts; a generous gift. 2. free from meanness or smallness of mind or character; magnanimous. 3. large; abundant; ample: a generous portion of pie. 4. rich or strong in flavor: a generous wine. 5. fertile; prolific: generous […]

• Generously

[jen-er-uh s] /ˈdʒɛn ər əs/ adjective 1. liberal in giving or sharing; unselfish: a generous patron of the arts; a generous gift. 2. free from meanness or smallness of mind or character; magnanimous. 3. large; abundant; ample: a generous portion of pie. 4. rich or strong in flavor: a generous wine. 5. fertile; prolific: generous […]

Disclaimer: Generic type variable definition / meaning should not be considered complete, up to date, and is not intended to be used in place of a visit, consultation, or advice of a legal, medical, or any other professional. All content on this website is for informational purposes only.