查找SML NJ对立面是否存在重复项
关于一个老问题,如果我想要相反的结果:查找SML NJ对立面是否存在重复项,sml,smlnj,Sml,Smlnj,关于一个老问题,如果我想要相反的结果: [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) 比如说
[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')
fun非重复ps=
案例ps
[]=>错误
|x::xs'=>(List.exists(fn y=>xy)xs')和also(非重复的xs')
不起作用
为什么???
谢谢。如果您想获得相反的结果,只需按如下方式定义函数:
fun non_duplicated xs = not (duplicated xs)
也就是说,您可以使用以下方法将not
推入复制的函数体:
非(a或b)(非a)和非(b)
不存在等于所有(不等于)
不假不假
然后你得到了相反的版本:
fun non_duplicated [] = true
| non_duplicated (x::xs) =
(List.forall (fn y => x <> y) xs) andalso (non_duplicated xs)
fun非重复[]=true
|非重复(x::xs)=
(List.forall(fn y=>x y)xs)和also(非重复xs)
如果要获得相反的结果,只需按如下方式定义函数:
fun non_duplicated xs = not (duplicated xs)
也就是说,您可以使用以下方法将not
推入复制的函数体:
非(a或b)(非a)和非(b)
不存在等于所有(不等于)
不假不假
然后你得到了相反的版本:
fun non_duplicated [] = true
| non_duplicated (x::xs) =
(List.forall (fn y => x <> y) xs) andalso (non_duplicated xs)
fun非重复[]=true
|非重复(x::xs)=
(List.forall(fn y=>x y)xs)和also(非重复xs)
假设ps是字符串列表假设ps是字符串列表