F # Implementing an interface, multiple parameters, getting errors in this override takes a different amount

I 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 as follows:

 type CarRentalService() = interface ICarRentalService with override this.CalculatePrice(pickupDate:DateTime, returnDate:DateTime, pickupLocation:string, vehiclePreference:string) = 5.5 

When compiling, I get the following compilation error:

 This override takes a different number of arguments to the corresponding abstract member 

Now I look at things and fight for an hour, what am I doing wrong?

+4
source share
1 answer

The method in your interface is declared in curry form, and your implementation is populated: in short: the method in the interface is a function that takes one argument and returns another function with the remaining arguments. In the opposite implementation, accepts all arguments in one part (packed in a tuple)

 open System type ICarRentalService = abstract member CalculatePrice: pickupDate:DateTime -> returnDate:DateTime -> pickupLocation:string -> vehiclePreference:string -> float let x : ICarRentalService = failwith "not implemented" let a = x.CalculatePrice // DateTime -> DateTime -> string -> string -> float let y = a (DateTime.Now) // DateTime -> string -> string -> float (first argument is bound) 

To fix the code, you need to either implement the curried implementation or declare-tupled. Curried version will not work with WCF, so consider using a fixed version

 type ICarRentalService = 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 
+6
source

All Articles