F# 实现接口,多个参数,出现错误此覆盖需要不同数量的
我在 F# 中定义了以下接口,
[<ServiceContract>]
type ICarRentalService =
[<OperationContract>]
abstract member CalculatePrice: pickupDate:DateTime -> returnDate:DateTime -> pickupLocation:string -> vehiclePreference:string -> float
然后尝试像这样实现它:
type CarRentalService() =
interface ICarRentalService with
override this.CalculatePrice(pickupDate:DateTime, returnDate:DateTime, pickupLocation:string, vehiclePreference:string) =
5.5
编译时出现以下编译错误:
This override takes a different number of arguments to the corresponding abstract member
我现在正在查看这个东西并摆弄了一个小时,我做错了什么?
I have defined the following interface in F#
[<ServiceContract>]
type ICarRentalService =
[<OperationContract>]
abstract member CalculatePrice: pickupDate:DateTime -> returnDate:DateTime -> pickupLocation:string -> vehiclePreference:string -> float
then I tried to implement it like this:
type CarRentalService() =
interface ICarRentalService with
override this.CalculatePrice(pickupDate:DateTime, returnDate:DateTime, pickupLocation:string, vehiclePreference:string) =
5.5
When compiling I get the following compile error:
This override takes a different number of arguments to the corresponding abstract member
I'm now looking at the thing and fiddling around for an hour, what do I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
接口中的方法以柯里化形式声明,并且您的实现是元组的:
简而言之:接口中的方法是接受一个参数并返回另一个带有剩余参数的函数的函数。在相反的实现中,接受一个片段中的所有参数(打包在元组中)
要修复代码,您需要使实现柯里化或声明 - 元组。柯里化版本不适用于 WCF,因此请考虑使用元组版本
Method in your interface is declared in curried form and your implementation is tupled:
if briefly: method in interface is function that accepts one argument and returns another function with remaining arguments. In opposite implementation accepts all arguments in one piece (packed in tuple)
To fix the code you need either to make implementation curried or declaration - tupled. Curried version will not work with WCF so consider using tupled version