On this page:
:  type
:  print-type
:  query-type/  args
:  query-type/  result
:  kind

7 Exploring Types🔗

In addition to printing a summary of the types of REPL results, Typed Racket provides interactive utilities to explore and query types. The following bindings are only available at the Typed Racket REPL.


(:type maybe-verbose t)

maybe-verbose = 
  | #:verbose
Prints the type t. If t is a type alias (e.g., Number), then it will be expanded to its representation when printing. Any further type aliases in the type named by t will remain unexpanded.

If #:verbose is provided, all type aliases are expanded in the printed type.

> (:type Number)

(U Exact-Number Imaginary Inexact-Complex Real)

[can expand further: Exact-Number Inexact-Complex Imaginary Real]

> (:type Real)

(U Negative-Real Nonnegative-Real)

[can expand further: Negative-Real Nonnegative-Real]

> (:type #:verbose Number)

(U 0



























(:print-type e)

Prints the type of e, which must be an expression. This prints the whole type, which can sometimes be quite large.

> (:print-type (+ 1 2))


> (:print-type map)

(All (c a b ...)


   (-> (-> a c) (Pairof a (Listof a)) (Pairof c (Listof c)))

   (-> (-> a b ... b c) (Listof a) (Listof b) ... b (Listof c))))


(:query-type/args f t ...)

Given a function f and argument types t, shows the result type of f.

> (:query-type/args + Integer Number)

(-> Integer Number Number)


(:query-type/result f t)

Given a function f and a desired return type t, shows the arguments types f should be given to return a value of type t.

> (:query-type/result + Integer)

(-> Integer * Integer)

> (:query-type/result + Float)


 (-> Flonum Flonum * Flonum)

 (-> Real Real Flonum Real * Flonum)

 (-> Real Flonum Real * Flonum)

 (-> Flonum Real Real * Flonum))


(:kind e)

Prints the kind of a well-kinded type-level expression e. When e is a type, it prints *. When e is a type constructor, -> following the open parenthesis in the printed result indicates e is productive and -o indicates otherwise.

> (:kind Integer)


> (:kind Listof)

(-> * *)

> (:kind Pairof)

(-> * * *)

> (:kind U)

(-o * ... *)

Added in version 1.15 of package typed-racket-lib.