I have made a **function** that checks for a **valid matrix**, a **function** that finds the **length of a list** and a **function** that states the **length of a row** and the **number of columns** in a matrix. What I need to know is how to write a **function** that **adds two matrices** together **WITHOUT MODULES**. I will show the **completed functions below**:

```
(* declaration of types intseq and intmatrix *)
type intseq = int list;;

type intmatrix = IM of intseq list;;

let getbody (IM x) = x;;

(* function getbody to retrieve the body of the intmatrix which is of type intseq list *)

let rec length: 'a list -> int =
  fun xs ->
  match xs with
    [] -> 0
  | (x::rest) -> 1 + length rest;;

(* test whether a list of lists of integers represents a matrix. 
   The length of each row should be equal.*)
let rec ismatrix x =

  match x with
    | IM([]) -> true
    | IM([[]]) -> true
    | IM([_]) -> true
    | IM(x::x2::rest) -> if (length x <> length x2)
        then false
        else ismatrix (IM(x2::rest));;

(* function matrixshape takes the matrix, and calculates the number of
   columns and rows *)
let rec matrixshape x =
  match x with
    | IM([]) -> (0,0)
    | IM([[]]) -> (0,0)
    | IM(x::rest) -> (length x,length rest + 1);;

(*A couple of extra functions I tried out \/ \/ \/*)
let rec seqadd : intseq -> intseq -> intseq =
  fun xs ys ->
  begin match xs, ys with
  | [], _ -> ys
  | _, [] -> xs
  | h::t, h2::t2 -> (h+h2)::(seqadd t t2)
  end;;

let rec rowadd: intseq list -> intseq list -> intseq list =
  fun row1 row2 ->
  match row1, row2 with
    | IM([[]]), IM([[_]]) -> row1
    | IM([[_]]), IM([[]]) -> row2
    | IM([[h::t]]), IM([[h2::t2]]) -> IM([[(h+h2)::(rowadd t t2)]]);;

(* matrix addition *)
let rec matrixadd: intmatrix -> intmatrix -> intmatrix =
  fun x y ->
(*TO DO*)

```