:- ensure_loaded(typeops).

% An example of type annotated Prolog:


% module posat
%
%    satisfy constraints over a poset
%


:- type_import(poset).  % import abstract type poset(T)



%----
% three kinds of constraints are handled
%
type po_constraint(T) -->
        T = T;
        T =< T;
        lub(T,list(T)).   % least upper bound


%----
% satisfy_constraints(PO,C) :-
%       constraints C are satified in poset PO,
%       C may contain logical variables when called.
%       PO must be a quasi-lattice.
%
pred satisfy_constraints(poset(@T),list(po_constraint(T))).
%
satisfy_constraints(_PO, []) :- !.
satisfy_constraints(PO, [X=Y|C]) :- !,
        X = Y,
        satisfy_constraints(PO,C).
satisfy_constraints(PO, [X=<Y|C]) :- !,
        po_leq(PO, X,Y),
        satisfy_constraints(PO,C).
satisfy_constraints(PO, [lub(Y,S)|C]) :- !, check(\+ S=[]),
        lubt_set(PO,S,Y),
        satisfy_constraints(PO,C).