[racket-dev] Is there a way to print out all inferred types for a typed racket program?

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Fri Sep 20 12:28:51 EDT 2013

No it is not easy.

It should all be there in the expanded output. TR stores the type of
an expression in a hashtable on the side, see
https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/types/type-table.rkt#L34.

So if you did

#lang racket
(require racket/pretty syntax/kerncase typed-racket/types/type-table)

(define prog #'(module tr typed/racket #:no-optimize "foo"))
(define expanded-prog (expand prog))
(pretty-print (syntax->datum expanded-prog))

(kernel-syntax-case expanded-prog #f
  ((module _ _
    (#%module-begin
       (module . _)
       (begin-for-syntax
         (module* . _))
       (begin-for-syntax . _)
       (#%plain-app _ (_ () body) _)
       . _))
   (type-of #'body)))

You should get the value, except that between the time that TR expands
the output and typechecks it and the time that it comes back from
expansion it has gotten changed so that the hash lookup will not work.

You can probably hack the internals of TR to export the original
syntax object out a side channel and do the same thing at it should
work.

You want the fully-expanded-syntax value here:
https://github.com/plt/racket/blob/master/pkgs/typed-racket-pkgs/typed-racket-lib/typed-racket/tc-setup.rkt#L64


On Thu, Sep 19, 2013 at 9:00 AM, John Smith <johnsmith at thurn.ca> wrote:
> I'm essentially looking for a dump of the typed AST of a given typed racket
> program for use in an undergraduate research project. Is there an easy way
> to get this information?
>
> _________________________
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
>

Posted on the dev mailing list.