我在试着学习F#和递归数组。我已经解决了递归总结一个数组现在我试图做同样的事情,除了这次匹配模式,但我不能得到它的工作帮助。F#数组和匹配模式
let myArray = Array.create 5 0
myArray.[0] <- 0
myArray.[1] <- 1
myArray.[2] <- 2
myArray.[3] <- 3
myArray.[4] <- 4
let rec sum (arr : int array) counter =
if counter = 0 then 0
else arr.[counter] + sum arr (counter - 1)
////////////////////////////////////////////////
// Can't get this to work.
let rec sum1 (arr : int array) counter =
match arr with
| [||] -> printfn "0"
| arr -> arr.[counter] + sum arr (counter - 1)
是不是'sum1'应该是递归的?你的意思是从'sum1'中调用'sum'? –