About using F # to create a Matrix assembly used with C #

There are no built-in matrix functions in C #, but there is Powerpack F # in them.

Instead of using a third-party or open-source C # library, I wonder about copying my file to F # and exposing the useful bits to C #.

I wonder if anyone thought about it or tried it, and is this a good idea.

Should I expose it to a class or load of static functions?

Or do I need to create a C # shell class and call this call before F #? Or does F # use the C # class as input and output?

Any thoughts?

Answer below : you can use the F # library directly in C # (operators too!):

using System;
using System.Text;
using Microsoft.FSharp.Math;

namespace CSharp
{
  class Program
  {
    static void Main(string[] args)
    {

        double[,] x = { { 1.0, 2.0 }, { 4.0, 5.0 } };
        double[,] y = { { 1.0, 2.0 }, { 7.0, 8.0 } };
        Matrix<double> m1 = MatrixModule.of_array2(x);
        Matrix<double> m2 = MatrixModule.of_array2(y);
        var mp = m1 * m2;

        var output = mp.ToArray2();
        Console.WriteLine(output.StringIt());

      Console.ReadKey();
    }
  }

  public static class Extensions
  {
    public static string StringIt(this double[,] array)
    {
      var sb = new StringBuilder();
      for (int r = 0; r < array.Length / array.Rank; r++)
      {
          for (int c = 0; c < array.Rank; c++)
          {
              if (c > 0) sb.Append("\t");
              sb.Append(array[r, c].ToString());
          }
          sb.AppendLine();
      }
      return sb.ToString();
    }
  }
}
+5
2

f #, #, ?

, FSharp.Core.dll,

Microsoft.FSharp.Math.BigInt class.

FSharp.PowerPack.dll,

Microsoft.FSharp.Math.Matrix<A> class
+6

XNA Framework Matrix. DLL, , , . , , ....

0

All Articles