【发布时间】:2018-08-11 07:54:25
【问题描述】:
这个问题可能听起来令人困惑,但基本上 我想制作一个接收列表和另一个函数的函数。现在通过该列表,我想获取在输入到此参数函数时返回 true 的元素的计数。我是 sml 的新手,所以我的错误是我打算向辅助函数添加一个计数并在 If 语句旁边增加它,但我很快就知道你不能真正增加 ml 中的值。有人可以解释一下更sml的方法吗?我只是想了解我所缺少的。
fun helper f nil counter = false
| helper f xs 1 = true
| helper f (x::xs) counter =
if (f x) = true then
counter = counter + 1
else
counter = counter + 0
fun numberExisting f alist = (helper f alist 0);
【问题讨论】: