Guidelines to design a C# library well usable from F#

后端 未结 2 2155
日久生厌
日久生厌 2021-02-08 00:22

I just want to point out that this is question is not the reverse of

Best approach for designing F# libraries for use from both F# and C#

Here I\'m not asking ho

2条回答
  •  隐瞒了意图╮
    2021-02-08 01:07

    Interop with existing .NET libraries was a major design goal of F#, so there aren't any constraints on the libraries to be consumed.

    That said, because of F#'s stricter typing, there are some patterns that result in slightly clunkier code. The builder pattern is one.

    var bldr = new StringBuilder();
    bldr.Append("abc"); //ignoring return value
    

    vs.

    bldr.Append("abc") |> ignore //must be explicitly ignored
    

    But this is easily worked around using an extension method or let-bound function. Bottom line: interop is one of F#'s strengths and greatest achievements.

提交回复
热议问题