[racket] typed racket: inconsistent interaction between typed and untyped code?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Fri Mar 4 16:20:20 EST 2011

I'm hitting an error when trying to pass values between typed and
untyped code.  I've shrunk the error to the following test code.
Consider three files 'sim-structs', 'sim.rkt', and 'test-sim.rkt'.
sim-structs and sim are written in Typed Racket, and test-sim is
written in regular racket.

;; sim-structs.rkt
#lang typed/racket/base
(provide (all-defined-out))
(define-struct: machine ([env : (Listof Any)]))  #:transparent)
(define-struct: toplevel ([vals : (Vectorof Any)])  #:transparent)

;; sim.rkt
#lang typed/racket/base
(require "sim-structs.rkt")
(provide new-machine)
(: new-machine ( -> machine))
(define (new-machine)
  (make-machine (list (make-toplevel (vector 'foobar)))))

;; test-sim.rkt
#lang racket
(require "sim.rkt" "sim-structs.rkt")
(toplevel-vals (first (machine-env (new-machine))))

When I try to execute test-sim, it fails with the following error:

tesla ~/work/js-sicp-5-5 $ /pro/plt/software/racket/5.1/std/bin/racket
contract violation: expected <toplevel?>, given: #<Typed Value:
#(struct:toplevel #(foobar))>
  contract on toplevel-vals24 from
    (file /home/dyoo/work/js-sicp-5-5/sim.rkt)
  contract: (-> toplevel? (vectorof Any))
        at: /home/dyoo/work/js-sicp-5-5/sim-structs.rkt:11.16

 === context ===
/home/dyoo/work/js-sicp-5-5/test-sim.rkt: [running body]

It looks as though there's some special "Typed Value" wrapper there
that shouldn't be visible from the untyped test-sim code.  Is there a

Posted on the users mailing list.