:- ensure_loaded(typeops).

% An example of type annotated Prolog:

%
% A few library predicates
%

:- type_import(prolog_types).   % import type 'list'


%-------
pred append(list(T),list(T),list(@T)).
%
append([],L,L).
append([H|T],L,[H|TL]) :- append(T,L,TL).


%-------
pred member(T,list(@T)).
%
member(X,[X|_]).
member(X,[_|T]) :- member(X,T).


%-------
% member_elim(X,LX,L) :-
%	X is member of list LX,
%	L is LX with a single occurence of X removed.
%
pred member_elim(T,list(@T),list(T)) .
%
member_elim(X,[X|T],R) :-  R=T.
member_elim(X,[Y|T],[Y|R]) :- member_elim(X,T,R).



%-------
pred reverse(list(@T),list(@T)).
%
reverse([],[]).
reverse([H|T],R) :- reverse(T,RT),append(RT,[H],R).


%-------
% same_length(L1,L2) :-
%       lists L1 and L2 have the same length.
%
pred same_length(list(_),list(_)).
%
same_length([],[]).
same_length([_|L1],[_|L2]) :- same_length(L1,L2).


%-------
% insert_uniq( X, L, XL ) :-
%       the list XL contains X and every member of list L,
%       if X is already member of L, then XL = L.
%
pred insert_uniq( T, list(T), list(@T)).
%
insert_uniq(X,L,XL) :- member(X,L), !, XL = L.
insert_uniq(X,L,[X|L]).  % not member(X,L).