轻量级语法和嵌套记录

轻量级语法和嵌套记录

该程序:

type A = { a : int }
type B = { b : A }

//34567890
let r = {
  b = {      // line 6
    a = 2    // line 7
  }
}

在mono/fsharpc下产生此警告两次:


  • 为什么根本会出现此警告? f#-spec p. 228让我认为在'{'之后的标记'a'设置了新的越位线,在这种情况下应该没有问题吗?
  • 为什么会出现两次?

  • 谢谢,

    索伦

    全输出:
    dcr > fsharpc foo.fs
    F# Compiler for F# 3.0 (Open Source Edition)
    Freely distributed under the Apache 2.0 Open Source License
    
    /Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (6:7). Try indenting this token further or using standard formatting conventions.
    
    /Users/debois/git/dcr/foo.fs(7,5): warning FS0058: Possible incorrect indentation: this token is offside of context started at position (6:7). Try indenting this token further or using standard formatting conventions.
    dcr >
    

    最佳答案

    将您的代码重新格式化为

    type A = { a : int }
    type B = { b : A }
    
    //34567890
    let r = { b = { a = 2 } }
    

    或者
    let r =
        {
           b = { a = 2 }
        }
    

    {是最左侧的 token 。

    编辑:一条异地行以{开头,因此您需要缩进至少与{一样,换行符不是必须的。第二个警告是由于相同的原因。

    关于f# - 轻量级语法和嵌套记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22266680/

    10-12 14:54