interface - F# 中的对象表达式和捕获的状态

标签 interface f#

是什么让第一个实现 KO ?

type IToto  = 
    abstract Toto : unit -> unit

{ new IToto with  
      member this.Toto = 
             fun () -> () }

{ new IToto with  
        member this.Toto () = ()  }

最佳答案

在编译表示中,函数类型的属性之间存在差异,编译为FSharpFunc<unit, unit> Toto { get; } , 以及取单元和返回单元的方法,编译为unit Toto() .

第一个对象表达式实现了一个不同的接口(interface):

type IToto  = 
    abstract Toto : (unit -> unit) // Note: Parentheses around the function type!

{ new IToto with  
      member this.Toto = 
             fun () -> () }

关于interface - F# 中的对象表达式和捕获的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15246660/

相关文章:

c# - 继承一个接口(interface),实现部分方法,让派生类实现其余部分

python - 如何在python中集成一个简单的菜单

java - 为什么不应该将两个集合接口(interface)一起实现?

c# - 使用动态类型作为它自己的基类型的参数

f# - 在 .net 5 中运行 Forms 表单 F# 脚本?

f# - F# 中的策略模式

包含空 Enum 的 Java 接口(interface)

java - 我应该实现哪个接口(interface)才能有解析方法

f# - 在 F# 中强制对函数进行多次计算

.net - F# 程序中的命令行参数?