F# 编译器警告:FS0058:可能缩进不正确

F# 编译器警告:FS0058:可能缩进不正确,f#,indentation,compiler-warnings,F#,Indentation,Compiler Warnings,我使用Visual Studio编写了此代码,但在编译时,它会返回以下警告: FS0058:可能缩进不正确,此标记与从位置9:80开始的上下文越位。尝试进一步缩进此标记或使用标准格式 但是,如果我尝试用OCaml编译器编译它,它会工作 let converti_tempo = (fun x -> if x < 0 then failwith "error" else if x < 1000 then (0, 0, x) else let rec m = x % 1000 le

我使用Visual Studio编写了此代码,但在编译时,它会返回以下警告:

FS0058:可能缩进不正确,此标记与从位置9:80开始的上下文越位。尝试进一步缩进此标记或使用标准格式

但是,如果我尝试用OCaml编译器编译它,它会工作

let converti_tempo = (fun x -> if x < 0 then failwith "error" else if x < 1000 then (0, 0, x) else 
let rec m = x % 1000
let s = (x / 1000) % 60
let mm = ((x / 1000) / 60) % 60
in (mm,s ,m ));;
让converti_tempo=(fun x->如果x<0,则失败,如果x<1000,则失败(0,0,x)否则
设rec m=x%1000
设s=(x/1000)%60
设mm=((x/1000)/60)%60
in(mm,s,m));;

在第一行末尾有一个
else
。这意味着
else
的表达式将在下一行定义,因此必须一直缩进else,然后再缩进一点。代码如下:

let converti_tempo = (fun x -> if x < 0 then failwith "error" else if x < 1000 then (0, 0, x) else 
                                                                                               let rec m = x % 1000
                                                                                               let s = (x / 1000) % 60
                                                                                               let mm = ((x / 1000) / 60) % 60
                                                                                               in (mm,s ,m ));;
让converti_tempo=(fun x->如果x<0,则失败,如果x<1000,则失败(0,0,x)否则
设rec m=x%1000
设s=(x/1000)%60
设mm=((x/1000)/60)%60
in(mm,s,m));;
你也可以这样写:

let converti_tempo = (fun x -> if x < 0 then failwith "error" 
                               else if x < 1000 then (0, 0, x) 
                               else
                                  let rec m = x % 1000
                                  let s = (x / 1000) % 60
                                  let mm = ((x / 1000) / 60) % 60
                                  in (mm,s ,m ));;
让converti_tempo=(乐趣x->如果x<0,则失败并显示“错误”
如果x<1000,则为(0,0,x)
其他的
设rec m=x%1000
设s=(x/1000)%60
设mm=((x/1000)/60)%60
in(mm,s,m));;

我认为这是一种更“惯用”的函数编写方式

let converti_tempo x =
    if x < 0 then
        failwith "error" 
    elif x < 1000 then
        (0, 0, x)
    else
        let m = x % 1000
        let s = x / 1000 % 60
        let mm = x / 1000 / 60 % 60
        (mm, s, m)
让converti_tempo x=
如果x<0,则
失败与“错误”
elif x<1000那么
(0,0,x)
其他的
设m=x%1000
设s=x/1000%60
设mm=x/1000/60%60
(毫米、秒、米)

对于我来说,此编译器警告是由我的一个“let”未正确对齐引起的。确保所有函数声明都从每一行的开头开始