我正在寻找有关问题的帮助。我正在尝试编写一个函数,它可以在ML中传递一个列表和函数。基本上,程序应该做的是获取一个列表并通过函数运行每个元素。如果函数返回true,那么元素将被添加到列表中,并且函数完成执行后返回列表。这里是我的代码:SML/NJ中的高阶函数
fun select(x:list, funct)= (* Define a new function that accepts a list and the prime function as a parameter*)
while (tl(x) not nil) do( (*While the tail is not empty*)
if funct(hd(x)) then (*Then run the function with the the head*)
val l = l::hd(x) (*Adds the head of x to the list *)
(*else 1+tl(x)*));
任何帮助将非常感激。
'不需要重新发明轮子......除非它是作业;) – 2012-02-04 23:44:12
是的,但是这个问题上没有作业标签:) – 2012-02-05 05:14:28
对不起,我没有指定。这是一项家庭作业。 – mikeyGlitz 2012-02-09 14:53:29