first impl of matrix.hs