Plt-redex: free hold hold exemption?

Every time I define a language in PLT redex, I need to manually define a replacement (capture) function. For example, this model is not completed because it is substnot defined:

#lang racket/base
(require redex/reduction-semantics)

(define-language Λ
  [V ::= x (λ x M)]
  [M ::= (M M) V]
  [C ::= hole (V C) (C M)]
  [x ::= variable-not-otherwise-mentioned])

(define -->β
  (reduction-relation Λ
    [--> (in-hole C ((λ x M) V))
         (in-hole C (subst M x V))]))

But the definition is substobvious. Can PLT redex handle substitution automatically?

+4
source share
1 answer

Yes! Just describe your language binding structure with the declaration #:binding-forms.

Here's a similar model with a non-capture substitution using the function substitute:

#lang racket/base
(require redex/reduction-semantics)

(define-language Λ
  [V ::= x (λ x M)]
  [M ::= (M M) V]
  [C ::= hole (V C) (C M)]
  [x ::= variable-not-otherwise-mentioned]
  #:binding-forms
  (λ x M #:refers-to x)) ;; "term M refers to the variable x"

(define -->β
  (reduction-relation Λ
    [--> (in-hole C ((λ x M) V))
         (in-hole C (substitute M x V))]))

(apply-reduction-relation -->β
  (term ((λ x (λ y x)) y)))
;; '((λ y«2» y))

Alphabetic equivalence is also provided free of charge, see alpha-equivalent?

(Thanks to Paul Stansifer !)

+4
source

Source: https://habr.com/ru/post/1664513/


All Articles