fork download
  1. :- set_prolog_flag(verbose,silent).
  2. :- prompt(_, '').
  3. :- use_module(library(readutil)).
  4.  
  5. :- set_prolog_flag(occurs_check,true).
  6. :- op(500,xfy,$).
  7.  
  8. % STLC type system specification
  9.  
  10. type(C,var(X), T) :- first(X:T,C).
  11. type(C,lam(X,E),A -> B) :- type([X:A|C], E, B).
  12. type(C,X $ Y, B) :- type(C,X,A -> B), type(C,Y,A).
  13.  
  14. first(K:V,[K1:V1|_]) :- K = K1, V=V1.
  15. first(K:V,[K1:_|Xs]) :- K\==K1, first(K:V, Xs). % no cut but use var cmp
  16.  
  17. main:-
  18. process,
  19.  
  20. type_and_print(C,E,T) :- type(C,E,T), print(E : T).
  21.  
  22. process:-
  23. /* your code goes here */
  24. type_and_print([],lam(x,var(x)),_), nl,
  25. type_and_print([],lam(x,lam(y,var(y)$var(x))),_), nl,
  26.  
  27. :- main.
Success #stdin #stdout 0.05s 7472KB
stdin
Standard input is empty
stdout
lam(x,var(x)): (_G1482->_G1482)
lam(x,lam(y,var(y)$var(x))): (_G1510-> (_G1510->_G1520)->_G1520)