【发布时间】:2013-02-08 07:13:34
【问题描述】:
关于一个较老的问题Find if Duplicates Exist SML NJ,如果我想要相反的结果:
[1,2,2,3,4,5,6] should return false
[1,2,3,4,5,6,7] should return true
[1,2,3,4,5,6,1] should return false
我怎样才能拥有它:
fun duplicated [] = false
| duplicated (x::xs) = (List.exists (fn y => x = y) xs) orelse (duplicated xs)
例如,
fun non_duplicated ps =
case ps of
[] => false
| x::xs' => (List.exists (fn y => x<>y) xs') andalso (non_duplicated xs')
没用。
为什么??? 谢谢。
【问题讨论】:
-
假设 ps 是一个字符串列表