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
// ...
这样的代码应该如何格式化?
解决方案
这是因为你的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
// ...
另请注意,有时您的缩进会优于编译器的建议。
推荐阅读
- android - Android Listview 从字符串单击加载图像
- github - MERN-Stack Heroku - 无法获取 /
- php - PHP:$a+++$a++的结果是什么
- javascript - ReactJs 中函数式组件的这两种用法有什么区别
- java - Solve Comparator 不为相等的元素返回 0
- python - 为什么我的图像没有保存?使用 TensorFlow Keras.preprocessing.image.directoryIterator
- python - python库'anytree'中的Findall()搜索功能返回NameError:'findall'未定义
- python - 通过电子邮件发送文本文件的内容
- javascript - 过滤掉数据库中没有关联产品的对象元素
- angular - 角度路由没有传递我的参数值