这是一个函数,我计算出一个等价类是一组完全等价的元素.而是迭代迭代矩阵列中的所有条目; 计算具有关系反射性的等价类并检查两个方向
let eq_class m i =
let column = m.(i)
and set = ref [] in
Array.iteri begin fun j l ->
if j = i || column.(j) && m.(j).(i) then
set := j :: !set else ignore l
end column;
!set;;
Run Code Online (Sandbox Code Playgroud)
你可以帮我解释一下l,我必须用来ignore传递编译器.如何在l不使用的情况下正确编写此功能ignore?
您可以替换ignore l为():它具有相同的类型并执行相同的操作(无).
else分支中的表达式应与分支中的表达式具有相同的类型then,并且分支中的表达式的类型then为unit.
此外,还有一个缩短的便利构造if condition then expression else ().等效结构较短if condition then expression,您可以在程序中使用:
let eq_class m i =
let column = m.(i)
and set = ref [] in
Array.iteri begin fun j l ->
if j = i || column.(j) && m.(j).(i) then
set := j :: !set
end column;
!set;;
Run Code Online (Sandbox Code Playgroud)