想象一下 C# 中的以下接口(interface):
interface IFoo {
void Bar();
}
如何在 F# 中实现这一点?我在 30 分钟的在线搜索中找到的所有示例仅显示具有返回类型的示例,我认为这些示例在函数式样式中更为常见,但在这种情况下我无法避免。
这是我到目前为止所拥有的:
type Bar() =
interface IFoo with
member this.Bar() =
void
_FS0010 失败:
Unexpected keyword 'void' in expression_.
最佳答案
等效的单位是在语法上定义为 ()
.
type Bar() =
interface IFoo with
member this.Bar () = ()
关于interface - 如何在 F# 中实现返回 void 的接口(interface)成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3067605/