Skip to content

Instantly share code, notes, and snippets.

@jrslepak
Created June 5, 2013 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrslepak/5717099 to your computer and use it in GitHub Desktop.
Save jrslepak/5717099 to your computer and use it in GitHub Desktop.
define-union-language behavior examples
#lang racket
(require redex)
(define-language L1
(a integer)
(e variable-not-otherwise-mentioned
(* e e)))
(define-language L2
(b string)
(e integer
(+ e e)))
(define-union-language Merged L1 L2)
(define-union-language TaggedUnion (L1. L1) (L2. L2))
(redex-match Merged e (term (+ 1 x)))
(redex-match TaggedUnion e (term (+ 1 x)))
(redex-match TaggedUnion e (term (* 1 x)))
(redex-match TaggedUnion a (term 1))
(redex-match TaggedUnion L1.a (term 1))
; define-union-language can be internal, but has to be done with
; names that are already defined as languages
; not allowed:
#; (define (foo x y t)
(define-union-language temp-lang x y)
(redex-match temp-lang e t))
; allowed:
(define (foo x y t)
(define-union-language temp-lang L1 L2)
(redex-match temp-lang e t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment