Tuple type abstract output type

Based on this kvb answer, this code compiles (F # 4) and runs:

type Untupler = abstract Apply : 'u * 'u -> 'u let myotherFun arg1 arg2 = printfn "myotherFun result is : %A %A" arg1 arg2 let myFunction tup1 tup2 (i:Untupler) = myotherFun (i.Apply tup1) (i.Apply tup2) let reskvb = myFunction (1,2) ("Hello","World") { new Untupler with member __.Apply (x,y) = snd (x,y) } 

But if the last line is replaced with the original answer:

 let reskvb = myFunction (1,2) ("Hello","World") { new Untupler with member __.Apply x = fst x } 

then the compiler complains about error FS0768: The "Apply" participant does not accept the correct number of arguments, 2 arguments are expected

I do not understand why the compiler does not seem to conclude that x is indeed a tuple. Or is there another question that I am missing? thanks.

+2
source share
1 answer

The reason for this is that when you start using interfaces, you switch to F # support for object-oriented programming, and in F # all OOP interaction methods are by default .

Thus, the Apply method is interpreted as a method that takes two arguments of a method, and not a function that takes one tuple as input.

+5
source

All Articles