【发布时间】:2020-12-24 06:36:04
【问题描述】:
根据分配的参数,我不能使用模式或折叠,这是解决更大问题的特定方法的玩具示例。
当我运行代码时,我自然会得到一个“0”。那么问题来了,怎么才能得到a_count的最终值呢?
fun num_counter(numbers: int list, a_number: int) =
let val count = 0
in
let fun count_num(numbers: int list, a_count: int) =
if null numbers
then 0
else if (hd numbers) = a_number
then count_num(tl numbers, count + 1)
else count_num(tl numbers, count)
in
count
end
end
【问题讨论】: