[racket] Defining a typed language
On Mon Oct 20 07:08:54 EDT 2014, Konrad Hinsen wrote:
> I have put the code on Github for easier access:
>
> https://github.com/khinsen/racket-typed-lang
>
> Once this works, it can serve as a template for others.
Thanks for posting this... I was just wondering whether you've considered using
datum->syntax here. It'd maybe not be the most elegant solution,
but it would at least give you a working language.
-- a-typed-lang/main.rkt -------------
#lang typed-racket/minimal
(require typed/racket
(only-in typed/racket
[#%module-begin tr:module-begin]
[require tr:require]))
(provide (except-out (all-from-out typed/racket) #%module-begin)
(rename-out [module-begin #%module-begin]))
(define-syntax (module-begin ix)
(syntax-case ix ()
[(_ rest ...)
(with-syntax
([rix
; tr:require keeps the meaning that it has in this module, but the
; s-exp as a whole lands in the *caller's* lexical context...
(datum->syntax ix (list #'tr:require 'a-typed-lang/more))])
#'(tr:module-begin
rix
rest ...))]))
-- a-typed-lang/more.rkt -------------
#lang typed/racket
(provide foo)
(: foo (Integer -> Integer))
(define (foo x)
(* 2 x))
-- example.rkt -----------------------
#lang a-typed-lang
(: x Integer)
(define x 42)
(displayln x)
(displayln (foo x))
(displayln (impersonator? foo))
The above works under v5.3.4, anyway.
Hope this helps... Evan