为什么不将下面的代码不能正常工作?
fun sum_list xs =
case xs of
[] => NONE
| x::xs' => SOME (x+sum_list xs')
此代码的工作好,而NONE,当它是零,当我删除一些。 我知道,对于一个空表零的总和是合理的答案。 但是,为什么下面的例子中失败?
更新:它制造按照迭戈的回答工作:
fun sum_list xs =
case xs of
[] => NONE
| x =>
let
fun slist x =
case x of
[] => 0
| x::xs' => x + slist xs'
in
SOME (slist x)
end