=========== Star Trek =========== /* facts */ outranks(picard, riker). outranks(riker, worf). outranks(riker, geordi). outranks(geordi, wesley). /* rules */ commands(X, Y) :- outranks(X, Y). commands(X, Y) :- outranks(X, Z), commands(Z, Y). /* queries: commands(picard, X). commands(riker, X). */ ====================== Simple Type Checking ====================== /* Facts */ type(i, int). type(j, int). type(k, int). type(x, real). type(y, real). /* Rules */ expectedtype(plus(E1,E2),T) :- type(E1,T), type(E2,T). /* Queries * * type(i, X) * type(x, X) * * // Type Checking * expectedtype(plus(i,x),int) * expectedtype(plus(i,x),real) * expectedtype(plus(i,i),int) * expectedtype(plus(x,x),real) * expectedtype(plus(i,j),int) * * // Type Inference * expectedtype(plus(i,j),X) * expectedtype(plus(x,y),X) * expectedtype(plus(i,y),X) * expectedtype(plus(i,X),int) * expectedtype(plus(i,X),real) * expectedtype(plus(X,Y),int) * expectedtype(plus(X,Y),real) */