gpt4 book ai didi

f# - F# 中的格式化警告

转载 作者:行者123 更新时间:2023-12-02 22:40:19 25 4
gpt4 key购买 nike

以下代码在每个 let 上触发格式化警告(“可能不正确的缩进”):

module UtilTests =
[<Test>] let simpleWithNth ()= true |> should be True
[<Test>] let negIndex () = true |> should be True
[<Test>] let tooBigIndex () = true |> should be True
[<Test>] let lastIndex () = true |> should be True

以下不是:

module UtilTests =
[<Test>] let simpleWithNth ()= true |> should be True
[<Test>] let negIndex () = true |> should be True
[<Test>] let tooBigIndex () = true |> should be True
[<Test>] let lastIndex () = true |> should be True

为什么它希望每个 let 比它上面的缩进更多? (有什么方法可以让 Visual Studio 2012 自动格式化吗?)

最佳答案

正如 Brian 在评论中所说,将属性应用于 let 的常用方法作用是把属性写在let前一行捆绑。我也希望你写的代码能工作,因为函数体在同一行,但显然,编译器不这么认为....

但是,还有另一种方法可以将属性应用于 let在您的示例中运行良好的函数:

module UtilTests = 
let [<Test>] simpleWithNth ()= true |> should be True
let [<Test>] negIndex () = true |> should be True
let [<Test>] tooBigIndex () = true |> should be True
let [<Test>] lastIndex () = true |> should be True

如果您正在编写递归函数,则需要这种样式 - 那么前面几行的属性将不起作用,您需要编写 let rec [<Foo>] foo () = ... and [<Bar>] bar () = ... .

关于f# - F# 中的格式化警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10867392/

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