F# F中的泛型模#

F# F中的泛型模#,f#,module,generics,F#,Module,Generics,在C#中,我可以编译 static class Foo<T> { /* static members that use T */ } 静态类Foo{/*使用T*/}的静态成员 结果是泛型的,不可实例化 什么是等效的F#代码模块我起初以为这将接近您想要的: type Foo<'a> private() = static member Blah (a:'a) = printfn "%A" a 输入Foo到目前为止,其他答案都有部分图片 typ

在C#中,我可以编译

static class Foo<T> { /* static members that use T */ }
静态类Foo{/*使用T*/}的静态成员
结果是泛型的,不可实例化


什么是等效的F#代码<代码>模块我起初以为这将接近您想要的:

type Foo<'a> private() =   
    static member Blah (a:'a) =
       printfn "%A" a

输入Foo到目前为止,其他答案都有部分图片

type Foo<'a> private() =          // '
    static member Blah (a:'a) =   // '
        printfn "%A" a

type foother类不能实例化它;就F#而言,构造函数对此F#类型是“私有的”。啊-因此F#尊重私有的,而不是实际的.net CLR限制。。。尽管如此,InternalsVisibleTo还是会将其泄露给c#程序集(我并不是说这是一个缺陷,只是在合法的不可信代码中是可能的)。我会更新答案的。请原谅我的无知,但是
/'
的诀窍是什么?我盯着代码看,不管有没有代码,它的行为都是一样的。非常感谢。
type Foo<'a> private() =          // '
    static member Blah (a:'a) =   // '
        printfn "%A" a
type Foo<'a> private() =             // '
    static let x = 0
    static do printfn "Static constructor: %d" x
    static member Blah (a:'a) =      // '
        printfn "%A" a

//let r = new Foo<int>() // illegal
printfn "Here we go!"
Foo<int>.Blah 42
Foo<string>.Blah "hi"