open System
type Foo() =
interface Collections.IEnumerable with
member x.GetEnumerator() = null
type Bar() =
interface Collections.IEnumerable with
member x.GetEnumerator() = null
interface Collections.Generic.IEnumerable<int> with
member x.GetEnumerator() = null
let xs, ys = Foo(), Bar()
for x in xs do() // <--
for y in ys do() // fine
上面的代碼產生以下編譯錯誤:這是一個F#編譯器錯誤嗎? #2
The type 'Foo' is not a type whose values can be enumerated with this syntax, i.e. is not compatible with either seq<_>, IEnumerable<_> or IEnumerable and does not have a GetEnumerator method.
代碼看起來完全合法和通用版本工作正常。這是一個F#編譯器錯誤?
感謝您的回答,托馬斯!實際上,我發現了這個錯誤,並在一小時前將它提交給[email protected] ... – ControlFlow 2010-10-04 15:14:43
@ControlFlow:啊,如果他們在一個小時內收到兩份報告,他們一定會更快地修復它:-)! – 2010-10-04 15:24:58