f# - optional parameters in abstract class type signature -
the class:
type notabstract () = member this.withoptionalparameters (x, ?y) = let y = defaultarg y 10 x + y
has following type signature:
type notabstract = class new : unit -> notabstract member withoptionalparameters : x:int * ?y:int -> int end
however, not work:
[<abstractclass>] type abstractexample () = abstract withoptionalparameters: int * ?int -> int /// ouch... type notabstract () = inherit abstractexample () override this.withoptionalparameters (x, ?y) = let y = defaultarg y 10 x + y
how write proper type signature in abstract definition of function optional parameters? did not find hint here.
ps: aware (similar) result achieved polymorphism
declaring argument option type doesn't make argument optional.
notabstract().withoptionalparameters(2) // expression expected have type // int * option<int> // here has type // int
the spec §8.13.6 has it:
in signature, optional arguments appear follows:
static member onenormaltwooptional : arg1:int * ?arg2:int * ?arg3:int -> int
naming optional argument in abstract member signature thus
[<abstractclass>] type abstractexample () = abstract withoptionalparameters: int * ?y:int -> int type notabstract () = inherit abstractexample () override this.withoptionalparameters (x, ?y) = let y = defaultarg y 10 x + y notabstract().withoptionalparameters(42) // val : int = 52
Comments
Post a Comment