What Is Type Inference? What It Is and How It Works
hackernoon.comThis is the blog version of my talk on type inference at GopherCon 2023 in San Diego, slightly expanded and edited for clarity.
What is type inference?
Wikipedia defines type inference as follows:
Type inference is the ability to automatically deduce, either partially or fully, the type of an expression at compile time. The compiler is often able to infer the type of a variable or the type signature of a function, without explicit type annotations having been given.
The key phrase here is “automatically deduce … the type of an expression”. Go supported a basic form of type inference from the start:
const x = expr // the type of x is the type of expr
var x = expr
x := expr
No explicit types are given in these declarations, and therefore the types of the constant and variables x
on the left of =
and :=
are the types ...
Copyright of this story solely belongs to hackernoon.com . To see the full text click HERE