通用参数的空列表
规范第 15.3 节提到序列 < >
中间有空格是允许的形式。它表示通用参数的空列表,这允许出现以下奇怪的情况。
type A() = class end
let a = new A< >()
为什么这是允许的?由于泛型类型可以在省略类型参数的情况下实例化,这是否是一种类型检查优化?
Section 15.3 of the spec mentions the sequence < >
with intervening whitespace is an allowed form. It indicates an empty list of generic arguments, which allows for the following oddity.
type A() = class end
let a = new A< >()
Why is this allowed? Since generic types can be instantiated with type args omitted, is this a type checking optimization of sorts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我同意 Ramon 的观点,它使事情更加一致,因为您可以将非泛型类型视为泛型 arity 0 类型的退化情况。对于泛型 arity“重载”的类型,这允许您更明确地说明您所指的类型:
在不仔细考虑重载解析的情况下,
t
的类型不一定很明显,但完全清楚t'
和t''
有。I agree with Ramon that it makes things more consistent, in that you can treat non-generic types as a degenerate case of types of generic arity 0. In the case of types which are "overloaded" by generic arity, this allows you to be more explicit about which type you're referring to:
Without thinking carefully about overload resolution, it's not necessarily obvious what type
t
has, but it's completely clear what typest'
andt''
have.我认为这只是为了一致性。您可以执行
List
和Dictionary
,因此您也可以执行int<; >
。I think it is just for consistency. You can do
List<int>
andDictionary<string, bool>
, so you can also doint< >
.