Advertisement
cciaranddunne

Untitled

Nov 4th, 2017
3,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun is_n_redex (LAM (x, APP(m, x'))) = if (ID x)=x' andalso not (contains x (freeVars m)) then true
  2.                                        else false
  3.   | is_n_redex (_)                   = false;
  4.  
  5. fun has_n_redex (APP (m, n)) = has_n_redex m orelse has_n_redex n
  6.   | has_n_redex (LAM (x, m)) = if is_n_redex (LAM (x, m)) then true
  7.                                else has_n_redex m
  8.   | has_n_redex (ID x)       = false;
  9.  
  10.  
  11. fun fst (APP (m, n)) = m;
  12. fun n_reduce (APP (m, n)) = if has_n_redex m      then APP (n_reduce m, n)
  13.                             else if has_n_redex n then APP (m, n_reduce n)
  14.                                                   else APP (m,n)
  15.   | n_reduce (LAM (x, m)) = if is_n_redex (LAM (x, m)) then fst m
  16.                             else LAM (x, n_reduce m)
  17.   | n_reduce (ID x)       = (ID x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement