f# - Tupled arguments in interfaces -


can explain f# curiosity?

    type ifoo =         abstract member bar1: int * int -> int * int         abstract member bar2: int * int -> (int * int)         abstract member bar3: (int * int) -> int * int      type foo() = class end                  interface ifoo             member this.bar1 (x, y) = (x, y)             member this.bar2 (x, y) = (x, y) // same impl bar1 i.e. parentheses on rhs of -> in interface member definition ignored             // member this.bar3 (x, y) = (x, y) // compile error: "this override takes different number of arguments corresponding abstract member"             member this.bar3 tuple = tuple // so, parentheses on lhs of -> in interface member definition *does* make difference! 

what difference in meaning between definitions of ifoo.bar1 , ifoo.bar3?

here, input type can describe 2 different things: tuple or argument list of cli method.

this makes no difference on return type, since interpretation of return type tuple. on argument list, can decide between cli method takes 2 arguments, or cli method takes 1 argument, happens tuple. latter denoted parentheses.

that why can implement bar3 single argument, typed tuple, isn't possible others (as of f# 3).

this place double parentheses make difference single parentheses. if bar3 weren't abstract, enforce tuple input declaring member this.bar3 ((arg1, arg2)).

method argument lists have additional features, such optional arguments. so:

type test () =     member t.bara(a, ?b) =     member t.bart((a, ?b)) = // error 

the last line gives error "optional arguments allowed on type members", since b part of tuple pattern, not argument in method's argument list.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -