У меня есть тип, реализующий IEnumerable<T>
интерфейс, все в порядке:Является ли это ошибкой F #?
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
Update более канонический пример:
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