为什么在此绑定函数中不需要上载? [英] Why upcast is not necessary in this let bound function?
本文介绍了为什么在此绑定函数中不需要上载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据 MSDN
将参数传递给方法时,将自动应用向上转换 在对象类型上.但是,对于模块中的绑定函数, 除非参数类型声明为 灵活的类型.
Upcasting is applied automatically when you pass arguments to methods on an object type. However, for let-bound functions in a module, upcasting is not automatic, unless the parameter type is declared as a flexible type.
但是
type C() =
member this.T() = ()
type D() =
inherit C()
let myfun (x: C)=
()
let d = D()
myfun d
我根本不需要上流.
推荐答案
看看 这意味着其推断类型在参数位置包括未密封类型的F#函数可以在调用时传递为子类型,而无需显式上载.例如:
(该示例显示的内容几乎与您的相同)
(The example showed there is almost the same as yours)
还请注意,对于绑定函数,除非在某些情况下(例如,当参数组成时,如果您的函数是:
Also note that for let bound functions upcasting is automatically except in some cases, for example when the argument is composed, if your function was:
let myfun (x: C option)=
()
上传不再自动.
这篇关于为什么在此绑定函数中不需要上载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文