How to convert between F # and C # roots?

I am writing an F # interaction class to be used with C #. I thought that F # had an implicit conversion from the .NET Tuple <> type (similar to IEnumerable processed as seq), so I wrote the following code:

type MyClass() = member this.MyMethod (t: Tuple<int, int>) = let meaningOfLife (t : int * int) = 42 meaningOfLife t 

This code cannot compile with the following error: error FS0001: it is expected that this expression will be of type int * int, but there is a type of Tuple

Then how to convert tuples between C # and F # (and vice versa)?

+6
source share
1 answer

If you are targeting .NET 4.0 or later, you do not need to specify a Tuple object. F # baskets are automatically compiled into Tuple. You can use:

 type MyClass() = member this.MyMethod (t: int * int) = let meaningOfLife (t : int * int) = 42 meaningOfLife t 

And it should work fine with C #.

+8
source

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


All Articles