[racket] Cyclic data structures in Typed Racket

From: Konrad Hinsen (konrad.hinsen at fastmail.net)
Date: Mon Sep 29 12:10:29 EDT 2014

Hi everyone,

I am trying to port code creating a cyclic data structure to Typed
Racket, but notice that this is not as straightforward as I expected.

Here is the untyped code I start from:

   #lang racket

   (struct foo (x) #:mutable)
   (struct bar (x))

   (define-values (f b)
     (shared ([f (foo b)]
              [b (bar f)])
             (values f b)))

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

Switching to Typed Racket and annotating the struct definitions, I get
an error message saying that make-placeholder and placeholder-set!
from racket/base are lacking type annotations. I also get the recommendation
to use require/typed for importing them. OK, let's try:

   #lang typed/racket

   (require/typed racket/base
     [#:opaque Placeholder placeholder?]
     [make-placeholder (-> Any Placeholder)]
     [placeholder-set! (-> Placeholder Any Void)])

   (struct foo ([x : bar]) #:mutable)
   (struct bar ([x : foo]))

   (define-values (f b)
     (shared ([f (foo b)]
              [b (bar f)])
             (values f b)))

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

Same error message... which is not really surprising. I suppose typed/racket
already requires racket/base, so my additional require/typed has no effect.
But how can I fix this? I don't see any way to exclude items from typed/racket.

Konrad.

Posted on the users mailing list.