plt-redex:捕获 - 避免免费替换?

时间:2016-12-22 05:52:52

标签: racket plt-redex

每次我在PLT redex中定义一种语言时,我都需要手动定义一个(避免捕获)替换函数。例如,此模型尚未完成,因为未定义subst

#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))]))

subst的定义很明显。 PLT redex可以自动处理替换吗?

1 个答案:

答案 0 :(得分:4)

是的!只需使用#:binding-forms声明来描述您的语言的绑定结构。

这是一个类似的模型,通过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))

字母等价也是免费的,请参阅alpha-equivalent?

(谢谢你Paul Stansifer!)