▼ |  | The Typed Racket Reference

1 | Type Reference
2 | Special Form Reference
3 | Libraries Provided With Typed Racket
4 | Utilities
5 | Exploring Types
6 | Typed Racket Syntax Without Type Checking
7 | Typed Regions
8 | Optimization in Typed Racket
9 | Legacy Forms
10 | Compatibility Languages
11 | Experimental Features

On this page:

: type
: print-type
: query-type/ args
: query-type/ result

5.3.6
top ← prev up next →

### 5`` 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.

> > syntax

> > (: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.

Examples:

> > (:type Number)

> (U Exact-Number Inexact-Complex Real Float-Imaginary Single-Flonum-Imaginary)
> [can expand further: Exact-Number Inexact-Complex Real]

> > (:type Real)

> (U Nonpositive-Real Nonnegative-Real)
> [can expand further: Nonpositive-Real Nonnegative-Real]

> > (:type #:verbose Number)

> (U 0 1 Byte-Larger-Than-One Positive-Index-Not-Byte Positive-Fixnum-Not-Index Negative-Fixnum Positive-Integer-Not-Fixnum Negative-Integer-Not-Fixnum Positive-Rational-Not-Integer Negative-Rational-Not-Integer Float-Nan Float-Positive-Zero Float-Negative-Zero Positive-Float-No-NaN Negative-Float-No-NaN Single-Flonum-Nan Single-Flonum-Positive-Zero Single-Flonum-Negative-Zero Positive-Single-Flonum-No-Nan Negative-Single-Flonum-No-Nan Exact-Imaginary Exact-Complex Float-Imaginary Single-Flonum-Imaginary Float-Complex Single-Flonum-Complex)

> > syntax

> > (:print-type e)

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

> > syntax

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

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

> > syntax

> > (: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.
top ← prev up next →