我目前有以下代码:
let private matchers = [|
{ new Matcher() with
member __.RegexExpr = RegexExpr("^(let)")
member __.TokenTypeCreator _ = TokenType.LET }
|]
我想知道是否可以在同一行中写出所有内容。类似于(非工作)的东西:
let private matchers = [|
{ new Matcher() with member __.RegexExpr = RegexExpr("^(let)"); member __.TokenTypeCreator _ = TokenType.LET }
|]
由于
答案 0 :(得分:2)
我也找不到这样做的语法。只需在成员之间放置任何内容即可在单行上声明接口:
type IFoo = abstract member A: int abstract member B: int;;
但是如果我尝试相同来实例化它,编译器会拒绝它:
{ new Foo with member this.A = 1 member this.B = 2 };;
---------------------------------^^^^^^
stdin(10,34): error FS0010: Unexpected keyword 'member' in expression. Expected incomplete structured construct at or before this point or other token.
我不得不说我有时希望F#对基于缩进的基于缩进的代码有一个统一的规则,就像Haskell那样。