For example, if I have written 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 = ...
It works well in F# by open Lib, However, if I want to consume it in C# (where I am only interested in types and member functions in Lib), each time I create a type I have to new Lib.A(...). It becomes rather annoying there is no way to omit the module names. Calling a static method like Lib.A.C() is even more of a hassle.
Then I try to replace module with namespace, each time I introduce some helper functions I have to create a new module with a new name. Occasionally I can manage to rearrange all helper functions into 1 module, but that would result in less readable code somehow.
What would be a better structure for this?
Wish I had: Using * = Lib.* for C#.
I think you already mentioned the best option in your answer – define the file with
namespacedeclaration at the top (this way, you can write justusing Libin C#) and then place all helper functions in modules.Helper functions that are clearly associated with some type (e.g. with
A) could be placed into a module namedA(similarly to F# functions in theListmodule that are associated with theList<'T>type).This is a bit more work, because you need to mark the module with a special attribute (to avoid name clash), but it will be easy to use from both F# and C# (and I think having nice use is more important than saving a few keystrokes when building the library):