F#中的对象表达和捕获状态 [英] object expression and captured state in F#

查看:89
本文介绍了F#中的对象表达和捕获状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个实现KO的原因是什么?

What makes the first implementation KO ?

type IToto  = 
    abstract Toto : unit -> unit

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

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


推荐答案

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

In the compile representation, there is a difference between property of a function type, compiled as FSharpFunc<unit, unit> Toto { get; }, and a method taking unit and returning unit, compiled as unit Toto().

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

The first object expression implements a different interface:

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

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

这篇关于F#中的对象表达和捕获状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆