Bri*_*ian 11
请注意,您可以使用签名文件来模仿朋友.
如果你想A成为朋友B,那么A可以访问B其他人无法看到的内部,你可以做到例如
// File1.fs
type B() =
let x = 42 // private field
member this.X = x // public getter
type A() =
member this.PeekInto(b : B) =
b.X
Run Code Online (Sandbox Code Playgroud)
但也有
// File1.fsi
type B =
new : unit -> B
// do not expose X in the signature
type A =
new : unit -> A
PeekInto : B -> int
Run Code Online (Sandbox Code Playgroud)
而现在A的实现可以看到,B.X但该程序的续集无法看到B.X.
签名文件非常适合创建任意封装边界.