【发布时间】:2012-04-19 11:05:49
【问题描述】:
我想编写一个函数来搜索列表并查找此列表中是否有任何重复值。该函数应返回一个布尔值。这是我所在的位置,但这不起作用...
fun myFunc [] = true
myFunc(x::xs) =
if(x=myFunc(xs)) then false
else myFunc(xs);
[1,2,2,3,4,5,6] should return true
[1,2,3,4,5,6,7] should return false
[1,2,3,4,5,6,1] should return true
谢谢!
【问题讨论】:
-
您知道 SML/NJ 支持集合吗?
-
不是,我的意思是你可以用set来检测你的list是否包含重复项。
标签: functional-programming sml smlnj