如何将记录元组解构为私有值
如何使用模块级 let 绑定将两个私有值绑定到元组中的记录?
type private T = {F:int}
let private a = {F=1}
let private b, private c = {F=2}, {F=3}
在此示例中,a
工作正常,但 b
和 c
的绑定均失败并出现错误:
错误 FS0410:类型
'T'
比它所使用的值、成员或类型'val patternInput : T * T'
更难访问
How do you use a module-level let binding to bind two private values to records in a tuple?
type private T = {F:int}
let private a = {F=1}
let private b, private c = {F=2}, {F=3}
In this example, a
works fine, but the bindings for b
and c
each fail with the error:
error FS0410: The type
'T'
is less accessible than the value, member or type'val patternInput : T * T'
it is used in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要了解为什么这不起作用,请使用 Reflector 对其进行反编译。您正在创建一个元组并立即解构它。无论如何,在调试模式下,中间元组都会创建为封闭类型的内部字段(模式匹配的实现细节)。当然,这使得它比
T
更容易访问,而T
是private
。我很好奇这是否是一个错误(看起来是这样)。编辑
它变得更奇怪......
以下无法编译(有语法错误),但如果类型是公共的并且使用
let
而不是let private
,则可以正常编译。我认为可以肯定地说模块级私有
let
绑定中的解构存在一些问题。To see why this doesn't work, decompile it with Reflector. You're creating a tuple and immediately destructuring it. In debug mode anyway, the intermediate tuple is created as an
internal
field of the enclosing type (an implementation detail of the pattern match). Of course, that makes it more accessible thanT
, which isprivate
. I'm curious to know if this is a bug (seems like it).EDIT
It gets weirder...
The following fails to compile (with syntax error), but compiles fine if the types are public and
let
, instead oflet private
, is used.I think it's safe to say destructuring in module-level private
let
bindings has some problems.