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);;
I am trying to check if a matrix is submatrix of another matrix. But I have to use type list list. And a I can't use any of the defined List functions. Obviously I am using List hd, tl but I will replace that.
A get an error when I try to call the function which I don't understand.
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 #
Please help!
I figured it out.
let rec does_it_contain (lis1, lis2) =
if rep lis1 = [] then false
else if rep lis2 = [] then false
else if ( glava lis1 = glava lis2) then true
else does_it_contain ( lis1, rep lis2);;
let rec does_it (matrica, matrica1) =
if rep matrica = [] then false
else if rep matrica1 = [] then false
else if does_it_contain ( glava matrica, glava matrica1) = true then true
else does_it ( rep matrica, rep matrica1);;
does_it(moja_matrika1, moja_matrika2);;
rep being an alternative for List.tl and glava an alternative for List.hd.