What type inference algorithm does the Go compiler use?
I tried looking this up on golang but I can't find documentation. I am tempted to assume that it would be Hindley-Milner, but I would like to know for sure
Type Inference — The compiler can infer the type of a variable or a function without us having to explicitly specify it. Go has Uni-directional type inference.
Type inference. The analyzer can infer types for fields, methods, local variables, and most generic type arguments. When the analyzer doesn't have enough information to infer a specific type, it uses the dynamic type.
Type inference refers to the process of determining the appropriate types for expressions based on how they are used. For example, in the expression f 3 , OCaml knows that f must be a function, because it is applied to something (not because its name is f !) and that it takes an int as input.
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.
Go certainly doesn't use Hindley-Milner. Why would you think that? In fact, Go doesn't have type inference in general, only with the :=
construct, and that uses the extremely simple rule of taking the evaluated type of the right-hand side and applying it to the newly-declared variable on the left. It's actually pretty darn similar to C++11's auto
keyword (except without the rules on handling const
and references).
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