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