[racket] Defining a typed language

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Wed Oct 1 11:27:48 EDT 2014

Hi everyone,

I'd like to define my own language that produces modules and code
considered "typed", as in Typed Racket. In fact, my language is
just a subset of Typed Racket plus a few new macros.

I started by writing "my-typed-lang.rkt":

   #lang typed/racket

   (provide define-foo
            #%module-begin #%top-interaction)

   (struct foo ([bar : Symbol]))

   (define-syntax-rule (define-foo id )
     (begin
       (: id foo)
       (define id (foo (quote id)))))

Then, a module that uses it:

   #lang s-exp "my-typed-lang.rkt"

   (define-foo x)

Running this results in the error message:

   ; Type Checker: Macro define-foo from typed module used in untyped code
   ;   in: (define-foo x)

This looks as if the module in my-typed-lang is considered untyped code.
Is there a way to fix this?

Note that I don't mind writing the my-typed-lang in untyped Racket if
that's what it takes. What I care about is having no expensive
contracts at the interface between Typed Racket and my-typed-lang.

Konrad.

Posted on the users mailing list.