英文:
Go's Type Inference Algorithm
问题
Go编译器使用什么类型推断算法?
英文:
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
答案1
得分: 23
Go确实不使用Hindley-Milner。你为什么会这样认为呢?事实上,Go一般没有类型推断,只有在使用:=
构造时才有,它使用了非常简单的规则,即将右侧的求值类型应用于左侧新声明的变量。实际上,这与C++11的auto
关键字非常相似(除了对处理const
和引用的规则)。
英文:
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论