#lang racket (require redex "subst.rkt") ;; ------------------------------------------------------------------ ;; SYNTAX (define-language Lam (e x (λ (x ...) e) (e e ...)) (x variable-not-otherwise-mentioned)) (define-extended-language Lam-red Lam (C hole (λ (x ...) C) (e ... C e ...))) ;; ------------------------------------------------------------------ ;; Full beta reduction -- also called general reduction (define ->λ (reduction-relation Lam-red #:domain e (--> (in-hole C ((λ (x ..._c) e_body) e ..._c)) (in-hole C (subst-n (x e) ... e_body))))) ;; ------------------------------------------------------------------ ;; TESTS (module+ test (test-equal (apply-reduction-relation* ->λ (term ((λ (x) w) z))) (list (term w))) (test-equal (apply-reduction-relation* ->λ (term (((λ (x) (λ (y) x)) w) z))) (list (term w))) ;; how many ways are there to reduce this expression? (define example (term (((λ (x) (λ (y) (x y))) (λ (z) y)) w))) (test-equal (apply-reduction-relation* ->λ example) (list (term y))) (traces ->λ example) (define omega (term ((λ (x) (x x)) (λ (x) (x x))))) (apply-reduction-relation* ->λ omega) (traces ->λ omega) (traces ->λ (term ((λ (y) (λ (z) z)) ,omega))) (traces ->λ (term ((λ (y) (λ (z) a)) ,omega))) (traces ->λ (term ((λ (y) (λ (z) y)) ,omega))))