[racket] Defining a typed language
Konrad Hinsen writes:
> I have added lots of comments to my minimalistic typed language
> implementation, in the hope that future language definers will
> be able to pick up from there:
>
> http://github.com/khinsen/racket-typed-lang
There is still one problem, although I am not convinced that it can be
fixed in the language definition.
The following code fails because 'foo' is considered an unbound identifier:
--- test1.rkt ------------------------------------
#lang racket/base
(module example a-typed-lang
(displayln (foo 42)))
(require 'example)
--------------------------------------------------
Strangely enough, as soon as my submodule has two forms it works, e.g.
--- test2.rkt ------------------------------------
#lang racket/base
(module example a-typed-lang
(displayln (foo 42))
(displayln (foo 42)))
(require 'example)
--------------------------------------------------
The documentation for "module" at
http://docs.racket-lang.org/reference/module.html?q=module#%28form._%28%28quote._~23~25kernel%29._module%29%29
suggests that single-form modules are handled differently than multi-form
modules, which might well explain this phenomenon. However, it doesn't provide
any clue to a solution. Apparently, my single form is
"partially expanded in a module-begin context. If the expansion
leads to #%plain-module-begin, then the body of the
#%plain-module-begin is the body of the module."
Furthermore:
"Finally, if multiple forms are provided, they are wrapped with
#%module-begin, as in the case where a single form does not expand
to #%plain-module-begin."
This suggests that if I want my single-form module to be handled exactly
like a multi-form module, my single form must expand to something else
than #%plain-module-begin. Fine. But who or what decides what my single
form becomes when it is "partially expanded in a module-begin context" ?
Konrad.