Tuples in type elements using F #

I have a simple question. Why is this not working?

type Test1() =
  member o.toTuple = 1.,2.,3.

type Test2() =
  member o.test (x: float, y: float, z: float) = printfn "test"
  member o.test (x: Test1) = o.test x.toTuple

Error:

Limit type mismatch. The type float * float * float is incompatible with the type Test1. The type "float * float * float" is incompatible with the type "Test1"

and

The type "float * float * float" is incompatible with the type "Test1"

+3
source share
2 answers

This does not work because the first test member is considered as a method with several arguments in case of overload. If you need a tuple, you need to add extra parentheses:

type Test2() =
    member o.test ((x: float, y: float, z: float)) = printfn "test"
    member o.test (x: Test1) = o.test x.toTuple

See Don Syme's explanation here .

: , :

type Test2() =
    member o.test (x: float, y: float, z: float) = printfn "test"
    member o.test (x: Test1) = let a,b,c = x.toTuple in o.test(a,b,c)
+5

Type2 , test. , , , .

type Test1() =
   member o.toTuple = 1.,2.,3.

type Test2() =
  member o.print (x: float, y: float, z: float) = printfn "test"
  member o.test (x: Test1) = o.print x.toTuple
+4

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


All Articles