I wanted to pass List from C# to F#.
I created this simple module.
(The pipes caracters are not printed !!)
namespace FSLIB
module Module =
let rec factorial n =
match n with
0 -> 1
n -> n * factorial (n - 1)
let factFromList (n : #seq<int>) =
let l = List.ofSeq n
let rec fact lst =
match lst with
[] -> 1
h :: t -> h * fact t
fact l
let rangeN a b =
[a..b] > List.toSeq
and here is how I use it from C#
using FSLIB;
namespace TestFSLIB
{
class Program
{
static void Main(string[] args)
{
var n = Module.factorial(5);
List<int> lst = new List<int>(Module.rangeN(1,10));
var fact10 = Module.factFromList(lst);
Console.Write(fact10);
Console.ReadLine();
}
}
}
Aucun commentaire:
Enregistrer un commentaire