大括号放置的 F# 约定

F# convention for brace placement

在 F# 中放置大括号是否有普遍接受的约定?我在文档 here 中找到了一些示例,但它们之间似乎并不一致。特别是,举一个实际的例子,关于哪个更好,这个

是否有共识?
seq {
    for polarity, a in Set.filter (fun (polarity, _) -> polarity) c do
    let c = Set.remove (polarity, a) c
    for a0, a1 in orientations (eqn a) do
    for polarity, b in Set.filter (fun (polarity, _) -> polarity) c do
    let c = Set.remove (polarity, b) c
    for b0, b1 in orientations (eqn b) do
    match unify a0 b0 with
    | None ->
        ()
    | Some m ->
        yield 
            c                                            
            |> Set.add (true, equal (a0, a1))                                        
            |> Set.add (false, equal (a1, b1))                                        
            |> evalClause m }

还是这个?

seq {
    for polarity, a in Set.filter (fun (polarity, _) -> polarity) c do
    let c = Set.remove (polarity, a) c
    for a0, a1 in orientations (eqn a) do
    for polarity, b in Set.filter (fun (polarity, _) -> polarity) c do
    let c = Set.remove (polarity, b) c
    for b0, b1 in orientations (eqn b) do
    match unify a0 b0 with
    | None ->
        ()
    | Some m ->
        yield 
            c                                            
            |> Set.add (true, equal (a0, a1))                                        
            |> Set.add (false, equal (a1, b1))                                        
            |> evalClause m 
}

类似地,对于列表和数组文字中的方括号,它们太大而无法写在一行中 - 通常是否遵循相同的约定?

很难评估 "generally accepted" 公约的构成...话虽如此,但还是有 F# formatting conventions, part of Fantomas, now also integrated in the Visual F# Power Tools。他们讨论了在记录和列表中放置大括号的问题。据此,记录的右大括号或列表的右括号 ] 应该在列表行上 - 只要包含的结构不太长。对于长结构,如您的示例中的情况,大括号应换行。

然而,they also say:

Not everyone likes this style, and variation is ok. For large constructs (> 6 lines) the closing token can be on a fresh line

没有明确提到 seq { ... },但我觉得同样的逻辑也适用于此。因此,您的第二个示例将是首选。

关于你问题的第二部分,关于数组和列表:如果你遵循 Fantomas 约定,短数组和列表将在列表项上结束,大的在新行上。