1

Lets say I have a C# class

namespace CSharp;
using FSharp;
class Point
{
    public double[] coords;
    double MyX
    {
        get
        {
            return FSharp.MyX(this);
        }
    }
}

And an F# method that would return a coordinate

namespace FSharp
open CSharp
let MyX (x : CSharp.Point) = x.coords.item 0

And this would be just fine but its circularly referencing because its 2 separate projects (in 1 solution). There would not be a problem if they were treated as if they are the same project, but VS does not let me do that and as far as I'm concerned, you cant use 2 coding languages in 1 project. At least I didnt find a way to do that.

My question is, how to accomplish such a thing?

Peri
  • 574
  • 1
  • 3
  • 19

1 Answers1

5

If your question is: "How can two projects reference types from each other", the answer is that you can't do that. Circular dependencies between projects are not allowed, see Circular dependencies.

Either extract a common type to a 3rd project that both projects reference, or find a way that one of your two projects don't need to reference this type at all.

Note also that if you were writing this in a single F# project, you'd run into the same problem since F#, unlike C#, also disallows circular dependencies (with some exceptions).

Asik
  • 21,506
  • 6
  • 72
  • 131
  • 2
    @TyCobb This is valid C#: `class A { B foo;} class B { A foo;}` A naive translation of this in F# would not compile. This is what I mean by that. – Asik Sep 10 '18 at 21:50
  • Ok. Was thinking of actual references (.dll) – TyCobb Sep 10 '18 at 21:52