Skip to content

Instantly share code, notes, and snippets.

@wilbowma
Created March 25, 2016 01:42
Show Gist options
  • Save wilbowma/4bc0ed97a60fa03dc07e to your computer and use it in GitHub Desktop.
Save wilbowma/4bc0ed97a60fa03dc07e to your computer and use it in GitHub Desktop.
#lang racket/base
(require
redex/reduction-semantics)
(define-language stlc
[t ::= nat (-> t t)]
[e m ::= natural x (λ (x : t) e) (e e)]
[x ::= variable-not-otherwise-mentioned]
[Γ ::= ∅ (Γ x : t)]
#:binding-forms
(λ (x : t) e #:refers-to x))
(define-metafunction stlc
Γ-in-dom : Γ x -> #t or #f
[(Γ-in-dom ∅ x)
#f]
[(Γ-in-dom (Γ x : t) x)
#t]
[(Γ-in-dom (Γ x_!_0 : t) (name x x_!_0))
(Γ-in-dom x)])
(define-metafunction stlc
Γ-ref : Γ x -> t
#:pre (Γ-in-dom Γ x)
[(Γ-ref (Γ x : t) x)
t]
[(Γ-ref (Γ x_!_0 : t) (name x x_!_0))
(Γ-ref Γ x)])
(define-metafunction stlc
Γ-ref_0 : Γ_0 x_0 -> t
#:pre (Γ-in-dom Γ_0 x_0)
[(Γ-ref_0 (Γ x : t) x)
t]
[(Γ-ref_0 (Γ x_!_0 : t) (name x x_!_0))
(Γ-ref_0 Γ x)])
(module+ test
(test-equal
(term (Γ-ref_0 (∅ x : nat) x))
(term nat))
(test-equal
(term (Γ-ref (∅ x : nat) x))
(term nat)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment