具有继承的类中的缩进规则?

时间:2019-03-30 12:15:55

标签: f#

我对F#编译器(通过Ionide)在缩进规则方面有些困惑。

这是触发警告的代码段:

type MyGame () as this =
  inherit Game ()
    let graphics = new GraphicsDeviceManager (this)
    let mutable spriteBatch = null
    let mutable state =
      {
        Board = Map.empty
        Selection = List.empty
      }

    do
      this.IsMouseVisible <- true

    // ...

但是当我在每行缩进前一行的一个或多个字符时,F#才看起来很高兴,这看起来对我来说很奇怪:

type MyGame () as this =
  inherit Game ()
    let graphics = new GraphicsDeviceManager (this)
      let mutable spriteBatch = null
        let mutable state =
          {
            Board = Map.empty
            Selection = List.empty
          }

          do
            this.IsMouseVisible <- true

    // ...

应如何格式化这样的代码?

1 个答案:

答案 0 :(得分:1)

这是因为您的inherit Game ()行的缩进不如接下来的缩进。更改缩进,警告消失:

type MyGame () as this =
    inherit Game ()
    let graphics = new GraphicsDeviceManager (this)
    let mutable spriteBatch = null
    let mutable state =
      {
        Board = Map.empty
        Selection = List.empty
      }

    do
      this.IsMouseVisible <- true

    // ...

还请注意,有时您的缩进将优于编译器建议的缩进。

相关问题