Files
mercury/tests/dppd/transpose_impl.m
Peter Ross 51497341cc Add the DPPD (dozens of problems in partial deduction) suite to the
Estimated hours taken: 0.1

Add the DPPD (dozens of problems in partial deduction) suite to the
tests directory.
1999-02-20 11:34:42 +00:00

48 lines
968 B
Mathematica

:- module transpose_impl.
:- interface.
:- import_module list.
:- pred transpose(list(list(T)), list(list(T))).
:- mode transpose(in(matrix9), out) is nondet.
:- mode transpose(in, out) is nondet.
:- inst matrix9 = bound([list9, ground, ground]).
:- inst list9 = bound([ground, ground, ground, ground, ground, ground, ground,
ground, ground]).
:- inst '.'(A, B)
---> '.'(A, B).
:- inst []
---> [].
:- implementation.
transpose(Xs,[]) :-
nullrows(Xs).
transpose(Xs,[Y|Ys]) :-
makerow(Xs,Y,Zs),
transpose(Zs,Ys).
:- pred makerow(list(list(T)), list(T), list(list(T))).
:- mode makerow(in, out, out) is semidet.
:- mode makerow(in(matrix9), out, out) is semidet.
makerow([],[],[]).
makerow([[X|Xs]|Ys],[X|Xs1],[Xs|Zs]) :-
makerow(Ys,Xs1,Zs).
:- pred nullrows(list(list(T))) is semidet.
:- mode nullrows(in) is semidet.
:- mode nullrows(in(list9)) is semidet.
nullrows([]).
nullrows([[]|Ns]) :-
nullrows(Ns).