How to use F # to process lists from C #

I am trying to figure out how to use the F # library from the C # assembly, I used C # quite often, but never used F #.

Here is class F # ..

namespace FLib
 type Class1() = 
    member this.square(x)=x*x
    member this.doit(x, op) = List.map op (Seq.toList(x))|>List.toSeq
    member this.squareAllDirect(x) = List.map this.square (Seq.toList(x))|>List.toSeq
    member this.squareAllIndirect(x) = this.doit x,  this.square

C # is used here

class Program
{
    static void Main(string[] args)
    {
        FLib.Class1 f = new FLib.Class1();
        List<int> l=new List<int>(){1,2,3,4,5};
        var q =f.squareAllDirect(l);
        var r = f.squareIndirect(l);
        foreach (int i in r)
            Console.Write("{0},",i);

        Console.ReadKey();
    }
}

The squareAllDirect function works as expected ... but calling squareAllIndirect from C # has an exception: The Type argument to the 'FLib.Class1.squareAllIndirect (System.Tuple, Microsoft.FSharp.Core.FSharpFunc'2>)' method cannot be output out of use. Try explicitly specifying type arguments.

+3
source share
1 answer

It looks like you expect your function to squareAllIndirecttake and returnint seq

However, if you click on it, you will see that it accepts and returns int seq * (int -> int)

Tuple , , x doit.

().

member this.squareAllIndirect(x) = this.doit(x,  this.square)

, , .

+3

All Articles