简体   繁体   中英

How to destucture a tuple of records to private values

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

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 than T , which is private . 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 of let private , is used.

type private T = {a:int; b:int}
let private t = {a=0; b=0}
let private {a=a; b=b} = t //syntax error

type private U() = class end
let private ul = [U()]
let private [u] = ul //syntax error

I think it's safe to say destructuring in module-level private let bindings has some problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM