Skip to content

Instantly share code, notes, and snippets.

@wilbowma
Created December 12, 2016 00:15
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 wilbowma/247d15e0e0bed6b239584854e79b5015 to your computer and use it in GitHub Desktop.
Save wilbowma/247d15e0e0bed6b239584854e79b5015 to your computer and use it in GitHub Desktop.
#lang racket
(begin-for-syntax
(require
racket
racket/syntax))
(define-for-syntax (typed-identifier x body)
(format-id x "~a1" x #:props (syntax-property
(syntax-property
x 'definition body #t)
'not-free-identifier=? #t #t)))
(define-syntax (define^ syn)
(syntax-case syn ()
[(_ id body)
(with-syntax ([x (typed-identifier #'id #'body)])
#`(begin
(define x body)
(define-syntax id
(make-rename-transformer #'x))))]))
(define-syntax (define^^ syn)
(syntax-case syn ()
[(_ id body)
(with-syntax ([x (generate-temporary)])
#`(begin
(define x body)
(define-syntax id
(make-rename-transformer
(syntax-property
(syntax-property #'x 'definition #'body #t)
'not-free-identifier=? #t #t)))))]))
(define-for-syntax (equal^? e1 e2)
(free-identifier=? (syntax-property e1 'definition) e2))
(define-for-syntax (my-expand e)
(local-expand e 'expression '()))
(define-syntax (:: syn)
(syntax-case syn ()
[(_ x e)
(unless (equal^? (my-expand #'x) #'e)
(error (format "Type error ~a ~a" #'x #'e)))
#`(void)]))
(define id^ (lambda (x) x))
(define^ id id^)
(define^^ id2 id^)
(:: id2 id^)
(:: id id^)
(provide :: id id2 id^)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment