> type XList<'T> (_collection : seq<'T>) =
inherit List<'T> (_collection)
member this.Add _item = if not <| this.Contains _item then base.Add _item
new() = XList<'T> (Seq.empty<'T>);;
inherit List<'T> (_collection)
--------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
stdin(47,9): error FS0945: Cannot inherit a sealed type
我的理解是,名单<“T>实际上不密封。没有?F#:无法从列表中<'T> F#互动继承
此外,这似乎在F#交互式以外工作得很好。这个确切的代码在我的F#项目中,编译器无需抱怨就可以处理它。我在几个C#项目中发生了同样的事情。代码在每种情况下都按预期工作。
通常情况下,我只是用一个静态方法(做它的“F#方法”)扩展List <'T>,但隐藏List.Add也应该很好。
谢谢,我知道SCGList和F#名单将最终咬我的屁股。现在打破我的樱桃。 – MiloDC 2011-06-11 04:50:20