16
有誰知道爲什麼這不能編譯?由於單元導致F#接口繼承失敗
type MyInterface<'input, 'output> =
abstract member MyFun: 'input -> 'output
type MyClass() =
interface MyInterface<string, unit> with
member this.MyFun(input: string) =()
//fails with error FS0017: The member 'MyFun : string -> unit' does not have the correct type to override the corresponding abstract method.
type MyUnit = MyUnit
type MyClass2() =
//success
interface MyInterface<string, MyUnit> with
member this.MyFun(input: string) = MyUnit
感謝Tomas。我還沒有在其他地方看到過這個問題(例如,在let的正常函數中) – 2010-12-19 23:43:07
@Stefan:如果使用'unit'類型作爲參數(函數或類型),那麼它通常很好。這個bug /限制可能只在實現抽象成員時纔會出現(這對F#編譯器來說有點棘手,因爲在.NET中繼承的複雜性非常複雜) – 2010-12-20 00:08:02
有趣的是,它可以在C#中工作,並且我可以使用F#中的函數。可能應該報告爲一個錯誤。 – 2011-01-12 05:55:38