Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找SML NJ对立面是否存在重复项_Sml_Smlnj - Fatal编程技术网

查找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是字符串列表