[racket] Cyclic data structures in Typed Racket

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Tue Sep 30 08:50:01 EDT 2014

Sam Tobin-Hochstadt writes:

 > Robby reminds me that we wrote a paper about another trick that might be useful here: 
 > http://www.ece.northwestern.edu/~robby/pubs/papers/stop2009-tf.pdf

Thanks, that's a nice approach. I had tried something similar (doing
the equivalent of a typecast), but hadn't thought of using the module
interface for this. I am also surprised to see that require/typed can
be used to import typed modules, but I am not complaining that it
works ;-)

It actually works fine when I use two modules in two separate files,
but when I tried using a submodule for the data definition, to keep
it with the client code, I ran into what is probably an unrelated
issue:

   #lang typed/racket

   (module cyclic typed/racket
     (provide (except-out (all-defined-out)) set-foo-x! set-bar-x!)
     (struct foo ([x : (U bar Void)]) #:mutable)
     (struct bar ([x : (U foo Void)]) #:mutable)
     (define f (foo (void)))
     (define b (bar (void)))
     (set-foo-x! f b)
     (set-bar-x! b f))

   (require/typed 'cyclic
     [#:struct foo ([x : bar])]
     [#:struct bar ([x : foo])]
     [f foo]
     [b bar])

   (eq? (bar-x b) f)
   (eq? (foo-x f) b)

require: unknown module
  module name: #<resolved-module-path:'cyclic>

If I convert the outer module to plain Racket and use a plain require,
this works fine. Are the rules for module references different in
Typed Racket?

Konrad.

Posted on the users mailing list.