这是我的代码的抽象:
module RootModule
module private SubModule = // I want everything in this module to be inaccessible from outside the file
let getLength s = String.Length s
type MyType (s: string) =
let _str = s
member this.GetStringLength = getLength _str // for sake of simplicity, a bogus method
let myExternalValue = new SubModule.MyType("Hello")
我收到错误Type 'MyType' is less accessible than the value, member, or type: 'val myExternalValue: SubModule.MyType' it is used in
为什么我不能拥有像这样的私有类实例的公共访问器?请注意,我正在使用RootModule
在不同的文件中,并且只希望有myExternalValue
在其他文件中可见
内部类型背后的想法是,没有其他程序需要访问该类型,因此,您应该能够编译一个单独的应用程序,就好像该类型不存在一样。然而,你违反了这个假设。特别是,调用程序如何知道如何调用该类型的任何方法?
您可以通过标记来修复此问题myExternalValue
作为内部。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)