为什么下面的代码不起作用?
fun sum_list xs =
case xs of
[] => NONE
| x::xs' => SOME (x+sum_list xs')
当它不是 NONE 它为零并且当我删除 SOME 时,此代码运行良好。我知道对于一个空列表的总和为零是合理的答案。但是为什么下面的例子失败了?
更新:通过遵循 Diego 的回答使其工作:
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