F# 由其他成员组成的枚举(标志)成员 [] 类型相似匹配= |无=0 |开始=1 |结束=2 |All=Start | | | End//ERROR:联合体中出现意外标识符

F# 由其他成员组成的枚举(标志)成员 [] 类型相似匹配= |无=0 |开始=1 |结束=2 |All=Start | | | End//ERROR:联合体中出现意外标识符,f#,F#,我还尝试使用枚举类型限定成员。在F#中有没有办法做到这一点?根据F#语言参考,没有办法做到这一点。F#枚举中=符号的右侧必须是整数文字 文法 [<Flags>] type LikeMatch = | None = 0 | Start = 1 | End = 2 | All = Start ||| End //ERROR: Unexpected identifier in union case 正如JaredPar所说,这种语言不允许这

我还尝试使用枚举类型限定成员。在F#中有没有办法做到这一点?

根据F#语言参考,没有办法做到这一点。F#枚举中=符号的右侧必须是整数文字

文法

[<Flags>]
type LikeMatch =
    | None  = 0
    | Start = 1
    | End   = 2
    | All   = Start ||| End //ERROR: Unexpected identifier in union case

正如JaredPar所说,这种语言不允许这样做,但F#确实有二进制文本,这使得显示正在设置的位变得很容易:

type enum-name =
   | value1 = integer-literal1
   | value2 = integer-literal2
开放系统
[]
类型相似匹配=
|无=0b00000000
|开始=0b000000001
|结束=0b000000010
|All=0b000000011
open System

[<Flags>]
type LikeMatch =
    | None  = 0b000000000
    | Start = 0b000000001
    | End   = 0b000000010
    | All   = 0b000000011