 %TWTYPES :- type transpose(matrix,matrix).

transpose(A,B) :-
        transpose_aux(A,[],B).

%TWTYPES :- type transpose_aux(matrix,matrix,matrix).

transpose_aux([R|Rs],_,[C|Cs]) :-
    rowtocol(R,[C|Cs],Cols1,Accm),
    transpose_aux(Rs,Accm,Cols1).
transpose_aux([], X, X).

%TWTYPES :- type row2col(row,matrix,matrix,matrix).

rowtocol([X|Xs],[[X|Ys]|Cols],[Ys|Cols1],[[]|As]) :-
    rowtocol(Xs,Cols,Cols1,As).
rowtocol([],[],[],[]).