I'm having trouble understanding how to write functions in ocaml as I've only written recursive functions that don't require multiple lines separated by a ;.
I'm trying to create a function that given a int number n returns a matrix full of zeroes and just ones in the diagonal, so an identity matrix of size n.
I'm new to functional programming and ocaml so I was wodering if it was possible to write this in a imperative way.
For example in Java I'd write:
public int[][] identity(int size) {
int[][] matrix;
matrix = new int[size][size];
//fill the matrix with zeroes
for( int i=0; i<size; i++){
for( int j=0; j<size; j++){
matrix[i][j] = 0;
}
}
//diagonal values at 1
for (int i=0; i<size; i++){
matrix[i][i] = 1;
}
return matrix;
}
How can I achieve this in ocaml?