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,但我会替换它。Submatrix Ocaml
当我尝试调用至少不理解的函数时出现错误。
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 #
请帮忙!
“_but我必须使用类型列表list_”: 如果你这样做的任何事情比学习别人,你不应该用列表来表示矩阵,这是非常低效的。 – ChriS
我知道,这是为了学校。 – Broda