【发布时间】:2011-04-23 20:12:39
【问题描述】:
有没有办法让泛型类型带有创建非泛型实例的无参数构造函数?非编译示例:
type Child<'T>() = class end
type Parent<'T>(c:Child<'T>) =
new() = Parent(Child<unit>()) // ERROR: This code is less generic than required by
// its annotations because the explicit type variable
// 'T' could not be generalized. It was constrained to be 'unit'.
我想要一个非泛型值以避免值限制,也因为我想使用 'T 进行重载(例如重载 Parent<int> 与 Parent<bool> 等)。
我认为这可能是不可能的,我需要找到一种不同的方式来建模事物。但也许有人有想法?
【问题讨论】: