Created
July 18, 2017 17:29
-
-
Save iitalics/e714b847a26e52dfc7a993325105eb31 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 turnstile | |
;; this is a silly language that allows the literal #t to be an Int. | |
;; you can decide lexically which expressions obey this property using (true=>int <expression>) | |
;; this is a test that the turnstile syntax works, because I don't yet have a "serious" language | |
;; to test the behavior with | |
(provide #%datum #%top-interaction true=>int | |
(type-out Int Bool)) | |
(define-base-type Int) | |
(define-base-type Bool) | |
(define-for-syntax true-is-an-int | |
(make-parameter #f)) | |
(define-typed-syntax #%datum | |
[(_ . n:integer) ≫ | |
-------- | |
[⊢ 'n ⇒ Int]] | |
[(_ . b:boolean) ≫ | |
#:with τ (if (and (syntax-e #'b) | |
(true-is-an-int)) | |
#'Int | |
#'Bool) | |
-------- | |
[⊢ 'b ⇒ τ]]) | |
(define-typed-syntax true=>int | |
[(_ e) ≫ | |
[⊢ [e ≫ e- ⇒ τ] #:with-param true-is-an-int #t] | |
-------- | |
[⊢ e- ⇒ τ]]) | |
(define-typed-syntax #%top-interaction | |
[(_ . e) ≫ | |
[⊢ e ≫ e- ⇒ τ] | |
-------- | |
[≻ (#%app- printf- '"~v : ~a\n" | |
e- | |
'#,(type->str #'τ))]]) | |
(require "tests/rackunit-typechecking.rkt") | |
(check-type #t : Bool) | |
(check-type #f : Bool) | |
(check-type 123 : Int) | |
(check-type (true=>int #t) : Int) | |
(check-type (true=>int #f) : Bool) | |
(check-type #t : Bool) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment