当我在 F# 中定义递归函数时:
let rec recursiveSum inputs =
let startState = 0.0m
if List.length inputs = 1 then
startState + inputs.Head
else
let t = List.tail inputs
startState + inputs.Head + recursiveSum t
...一切都很好。当我试图避免“空列表”问题时:
let rec recursiveSum inputs =
let startState = 0.0m
**if List.isEmpty inputs then startState**
if List.length inputs = 1 then
startState + inputs.Head
else
let t = List.tail inputs
startState + inputs.Head + recursiveSum t
......我被大喊大叫:
recursion.fsx(5,9): error FS0001: This expression was expected to have type
unit
but here has type
decimal
我在这里想念什么?