Argument trap and interface inheritance in fsharp

Is there any real reason why KO doesn't work?

  type IBase = 
      abstract member test : (unit * unit) -> unit

  type OK() = 
      interface IBase with

        member x.test ((titi,tata)) = () //OK

  type KO() = 
      interface IBase with

        member x.test (titi,tata) = () //fail : This override takes a different number of arguments to the corresponding abstract member    
+4
source share
2 answers

Since the brackets mean something in F # (this indicates a tuple), so they do not match.

As indicated, a method testis defined as a method that takes a tuple of two values ​​as arguments unit. If you use Reflection to get MethodInfo, the method is defined as:

Void test(System.Tuple`2[Microsoft.FSharp.Core.Unit,Microsoft.FSharp.Core.Unit])

This is consistent with the method OK, but not the method KO.

If you redefine the interface for

type IBase = 
    abstract member test : unit * unit -> unit

Then it OKdoes not compile, but KOdoes.

test, :

Void test(Microsoft.FSharp.Core.Unit, Microsoft.FSharp.Core.Unit)
+8
abstract member test : (unit * unit) -> unit

, , , , . http://msdn.microsoft.com/en-us/library/dd483468.aspx

- , 2 , 2

:

abstract member test : unit * unit -> unit
+6

Source: https://habr.com/ru/post/1541648/


All Articles