gpt4 book ai didi

f# - 轻量级语法和嵌套记录

转载 作者:行者123 更新时间:2023-12-04 18:42:37 25 4
gpt4 key购买 nike

这个程序:

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

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

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

/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.


  • 为什么会出现这个警告? 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 }
    }

    { 是最左边的标记。

    编辑:一个场外行以 { 开头,因此您需要至少缩进与 { 一样多的缩进,换行之后不是强制性的。而第二个警告也是出于同样的原因。

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

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com