[racket] Cyclic data structures in Typed Racket
Sam Tobin-Hochstadt writes:
> I recommend doing the mutation yourself, and not using `shared`.
> That's the most obvious solution.
Not for me, unfortunately, but probably I am missing something
obvious.
Here's explicit mutation in untyped Racket:
#lang racket
(struct foo (x) #:mutable)
(struct bar (x))
(define f (foo (void)))
(define b (bar f))
(set-foo-x! f b)
(eq? (bar-x b) f)
(eq? (foo-x f) b)
That works fine. Moving to Typed Racket, this is rejected by the type
checker because (void) is of type Void. Since I need a bar to make a
foo and a foo to make a bar, I don't see how I can ever initialize my
foo structure.
> The reason that your `require/typed` doesn't work is that it creates
> new versions of the placeholder functions, but those aren't the ones
> that `shared` uses internally, so Typed Racket doesn't use the types
> you've given.
That makes sense, thanks for the explanation!
Konrad.