How to show the type as friendly as possible for both C # and F #?

For example, if I wrote a module in F #

module Lib

type A =
    member this.x1 x = ...

let helpa x = ...
let helpb x = ...

type B =
    member this.y1 x = ...

let helpc x = ...

typeA with
    member this.x2 x = ...
typeB with
    member this.y2 x = ...

Works well in F # on open Lib. However, if I want to use it in C # (where I am only interested in types and member functions in Lib), every time I create a type, I have to new Lib.A(...). This becomes quite annoying, so module names cannot be ignored. Calling a static method, such as Lib.A.C(), is even more complicated.

Then I try to replace modulewith namespace, every time I introduce some helper functions, I need to create a new module with a new name. Sometimes I manage to rearrange all auxiliary functions in 1 module, but this will lead to the fact that the code will be less clear.

What would be better for this?

: Using * = Lib.* #.

+5
2

, - namespace ( , using Lib #), .

, - (, A), A ( F # List, List<'T>).

, ( ), F #, # ( , ):

namespace Lib

// Declaration of the 'A' type and helper functions in 'A' module 
type A() =
  member this.x1 x = 10

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module A = 
  let helpa (x:A) = x.x1
  let helpb (x:A) = x.x1

// Declaration of the 'B' type and helper functions in 'B' module 
type B() =
  member this.y1 x = 10

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module B = 
  let helpc (x:B) = x.y1

// Member augmentations for easy use from C#
type A with
    member this.x2 x = A.helpa this
type B with
    member this.y2 x = B.helpc this
+4

F # , # , # , , . - , , :

namespace Lib

type A =
    member this.x1 x = ()

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module A =
  let helpa x = ()
  let helpb x = ()

type B =
    member this.y1 x = ()

[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module B =
  let helpb x = ()

type A with
    member this.x2 x = ()
type B with
    member this.y2 x = ()

F # . [<AutoOpen>] [<RequireQualifiedAccess>] F #.

+7

All Articles