【发布时间】:2015-08-05 07:04:53
【问题描述】:
我正在尝试掌握 F#,并且在此过程中我正在转换一些 C# 代码。我在定义接口中的属性并在类型中实现它们时遇到了一些麻烦。
考虑以下代码:
module File1
type IMyInterface =
abstract member MyProp : bool with get, set
abstract member MyMethod : unit -> unit
type MyType() =
interface IMyInterface with
member val MyProp = true with get, set
member self.MyMethod() = if MyProp then () else ()
The documentation for F# properties 似乎表明我在 MyType 中的 MyProp 实现是正确的,但是,编译器抱怨“未定义值或构造函数 'MyProp'”。有什么想法吗?
【问题讨论】:
-
试试
self.MyProp- 你需要this限定符;) -
@Carsten 似乎不适用于自动属性
标签: interface f# automatic-properties