我目前正在学习 SML,我很难理解下面的代码
fun good_max (xs : int list) =
if null xs
then 0
else if null (tl xs)
then hd xs
else
(* for style, could also use a let-binding for (hd xs) *)
let val tl_ans = good_max(tl xs)
in
if hd xs > tl_ans
then hd xs
else tl_ans
end
Run Code Online (Sandbox Code Playgroud)
hd xs是类型,int并且tl_ans,我认为是类型list。为什么这段代码有效?系统如何评估递归?xs = [3, 4, 5]如果您能向我展示这是如何工作的,那就太好了。