Type inference

Type inference (also inferred and infer), is when the type of a variable or missing word is decided in an automatic way using rules to check if it is correct for a specific purpose. For example, we could fill in the blank (_) of a phrase "sing a _." If "song" is used to replace the blank, then we get the usable phrase of "sing a song." If instead we replaced the blank with the word "friend", in English, we get a type of phrase that makes no sense. The phrase is correct based on the word chosen and English rules of grammar.

In the below example, we will apply this logic to a variable () of the integer type ():

var = 1 // the type of variable is unknown
int var = 1 // the type of variable is known (integer)

In various programming languages, the type can be inferred by the compiler and its internal rules. The programmer does not have to decide and instead the compiler does so.

Uses

Some notable languages that include type inference: C, C++, C# (from version 3.0), D,  F#, FreeBASIC, Go, Haskell, Java (from version 10), Julia, Kotlin, OCaml, Rust, Scala, Swift, TypeScript, and V (Vlang).

References

Category:Computer science
Category:Computer terminology