【发布时间】:2017-09-10 01:43:30
【问题描述】:
let moja_matrika1 = [[1; 2]; [3; 4]];;
let moja_matrika2 = [[4; 7; 8]; [3; 2; 1]];;
let rec does_it_contain (lis1, lis2) =
if (List.hd lis1 = []) then false
else if (List.hd lis1 = lis2) then true
else does_it_contain ((List.tl lis1), lis2);;
let rec does_it (matrix, lis1) =
if (matrix = []) then false
else if does_it_contain (List.hd matrix, List.hd lis1) = true then true
else does_it (List.tl matrix, lis1);;
does_it (moja_matrika1, moja_matrika2);;
我正在尝试检查一个矩阵是否是另一个矩阵的 sbumatrix。但我必须使用类型列表列表。而且我不能使用任何定义的 List 函数。显然我正在使用 List hd,tl 但我会替换它。
当我尝试调用我不理解的函数时出现错误。
does_it (moja_matrika1, moja_matrika2);;
Error: This expression has type int list list
but an expression was expected of type 'a list list list
Type int is not compatible with type 'a list #
请帮忙!
【问题讨论】:
-
"但我必须使用类型列表列表":如果你这样做是为了学习以外的任何其他事情,你不应该使用列表来表示矩阵,这是非常低效的。
-
我知道,这是给学校的。