:-module(_,[list_diff/3],[]).

'$applied_packages'([prelude,nonpure,condcomp,assertions,regtypes,rtchecks_shallow,predefres(res_steps),resdefs,resdefs/resources_decl,nativeprops,basicmodes,argnames,expander]).

:-pred list_diff(A,B,C):(listgnd(A),listgnd(B),var(C))=>listgnd(C).

list_diff(_1,_2,_3) :-
        'list_diff$pre'(_1,_2,_3,_4),
        'list_diff$cls'(_1,_2,_3),
        'list_diff$post'(_1,_2,_3,_4).
'list_diff$pre'(_1,_2,_3,_7) :-
        reify_check(listgnd(_1),[_1],_5),
        reify_check(listgnd(_2),[_2],_6),
        reify_check(var(_3),[_3],_4),
        _8 is _4/\(_5/\_6),
        _7 is _8,
        _9 is _7,
        warn_if_false(_9,'CP').
'list_diff$post'(_,_,_1,_3) :-
        reify_check(listgnd(_1),[_1],_2),
        _4 is _2,
        _5 is _3#1\/_4,
        _6 is _5,
        warn_if_false(_6,'AP').
'list_diff$cls'([],_L,[]).
'list_diff$cls'([H|L1],L2,L3) :-
        memberchk(H,L2),
        !,
        list_diff(L1,L2,L3).
'list_diff$cls'([H|L1],L2,[H|L3]) :-
        list_diff(L1,L2,L3).
memberchk(X,[X|_]) :-
        !.
memberchk(X,[_|L]) :-
        memberchk(X,L).


:-prop listgnd/1+regtype.
listgnd([]).
listgnd([_|T]) :-
        gnd_,
        listgnd(T).