我有一個正在實施IEnumerable<T>
接口的類型,一切正常:這是一個F#bug嗎?
open System
type Bar() =
interface Collections.IEnumerable with
member x.GetEnumerator() = null
interface Collections.Generic.IEnumerable<int> with
member x.GetEnumerator() = null
但如果類型繼承通過基本類型IEnumerable
接口實現的東西出了問題:上面
open System
type Foo() =
interface Collections.IEnumerable with
member x.GetEnumerator() = null
type Bar() =
inherit Foo()
interface Collections.Generic.IEnumerable<int> with
member x.GetEnumerator() = null
代碼生成型推理錯誤:
The member 'GetEnumerator<'a0 when 'a0 : null> : unit -> 'a0 when 'a0 : null' does not have the correct type to override any given virtual method
The member 'GetEnumerator<'a0 when 'a0 : null> : unit -> 'a0 when 'a0 : null' does not have the correct number of method type parameters. The required signature is 'GetEnumerator : unit -> Collections.Generic.IEnumerator<int>'.
我做得不對或這是F#編譯器錯誤?
Microsoft (R) F# 2.0 Interactive build 4.0.30319.1
更新更典型的例子:
type IFoo = abstract Bar : obj list
type IFoo<'a> = abstract Bar : 'a list
inherit IFoo
/* ok */
type Foo = interface IFoo with member x.Bar = []
interface IFoo<Foo> with member x.Bar = []
/* fail */
type FooBase = interface IFoo with member x.Bar = []
type FooDerived = interface IFoo<Foo> with member x.Bar = [] // <---
inherit FooBase
/*
error FS0017: The member 'get_Bar : unit -> 'a list' does not
have the correct type to override any given virtual method.
*/
你能發佈你的實際代碼嗎? – Gabe 2010-10-04 14:38:35