简体   繁体   中英

.net seamless c# + f#

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM