我试图在非递归阶乘函数中从 6 倒数到 1 并得到编译器错误:
let fact x =
let mutable product = 1
for i in x..-1..1 do
product <- product * i
product
// Error on the 6 - type 'int' does not support the operator '..-'
let answer = fact 6
printfn "%i" answer
已将功能更改为仅计数并且可以正常工作,但是我很想知道为什么会失败。有没有更好的倒计时方法?
使用VS2012更新3