Go的类型推断算法 [英] Go's Type Inference Algorithm
问题描述
Go编译器使用什么类型的推理算法?
我试图在golang上查找这个,但是我找不到文档。我很想假设它会是Hindley-Milner,但我想确切知道
不要使用Hindley-Milner。你为什么那么想?实际上, Go通常不具有类型推断,只能使用:=
构造,并且使用非常简单的规则评估右侧的类型并将其应用于左侧新声明的变量。它实际上非常类似于C ++ 11的 auto
关键字(除非没有处理 const
和引用的规则)。
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
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).
这篇关于Go的类型推断算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!