Advertisement
cciaranddunne

Untitled

Nov 6th, 2017
2,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun is_b_redex (APP (LAM (x, m), n)) = true
  2.   | is_b_redex (_)                   = false;
  3.  
  4. fun has_b_redex (APP (m, n)) = if is_b_redex (APP (m,n)) then true  
  5.                                else has_b_redex m orelse has_b_redex n
  6.   | has_b_redex (LAM (x, m)) = has_b_redex m
  7.   | has_b_redex (ID x)       = false;  
  8.  
  9. (*Created two pattern matching functions to avoid having to write
  10.   two different patterns for an application that is a redex, and one
  11.   that may or may not contain a redex.*)
  12. fun bdy (LAM (x, m)) = m;
  13. fun var (LAM (x, m)) = x;
  14.  
  15. fun lb_reduce (APP (m, n)) = if is_b_redex (APP (m,n)) then subs n (var m) (bdy m)
  16.                              else if has_b_redex m then APP (lb_reduce m, n)
  17.                              else if has_b_redex n then APP (n, lb_reduce m)
  18.                                                    else APP(m, n)
  19.   | lb_reduce (LAM (x, m)) = lb_reduce m
  20.   | lb_reduce (ID x)       = (ID x);
  21.  
  22. fun rb_reduce (APP (m, n)) = if is_b_redex (APP (m,n)) then subs n (var m) (bdy m)
  23.                              else if has_b_redex n then APP (n, rb_reduce m)
  24.                              else if has_b_redex m then APP (rb_reduce m, n)
  25.                                                    else APP(m, n)
  26.   | rb_reduce (LAM (x, m)) = rb_reduce m
  27.   | rb_reduce (ID x)       = (ID x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement