Can’t figure out why the pattern matching isn’t working! I’m beginning with Hasklell, so be patient!
-- matrix implemented as a list of lists (rows of the matrix)
test_matrix3 = [[1,0,0],[2,-3,0],[4,5,6]]
-- transpose of a given matrix
transpose (x:[]) = [x]
transpose all@(x:_) = map head all : transpose ([tail y | y <- all])
Executing:
*Main> transpose test_matrix3
[[1,2,4],[0,-3,5],[0,0,6],[*** Exception: Prelude.head: empty list
This one worked for me:
Test: