Created
December 12, 2016 00:15
-
-
Save wilbowma/247d15e0e0bed6b239584854e79b5015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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