4

每次我在 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 可以自动处理替换吗?

4

1 回答 1

5

是的!只需用#: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?

(谢谢保罗斯坦西弗!)

于 2016-12-22T05:52:52.093 回答