▼ |  | 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

► | 1 | Type Reference

1.1 | Base Types
1.2 | Singleton Types
1.3 | Containers
1.4 | Syntax Objects
1.5 | Control
1.6 | Other Type Constructors
1.7 | Other Types

On this page:

Any
Nothing
1.1`` Base Types
1.1.1`` Numeric Types
Number
Complex
Integer
Float
Flonum
Single-Flonum
Inexact-Real
Exact-Rational
Real
Exact-Number
Float-Complex
Single-Flonum-Complex
Inexact-Complex
Positive-Integer
Exact-Positive-Integer
Nonnegative-Integer
Exact-Nonnegative-Integer
Natural
Negative-Integer
Nonpositive-Integer
Zero
Positive-Float
Positive-Flonum
Nonnegative-Float
Nonnegative-Flonum
Negative-Float
Negative-Flonum
Nonpositive-Float
Nonpositive-Flonum
Float-Negative-Zero
Flonum-Negative-Zero
Float-Positive-Zero
Flonum-Positive-Zero
Float-Zero
Flonum-Zero
Float-Nan
Flonum-Nan
Positive-Single-Flonum
Nonnegative-Single-Flonum
Negative-Single-Flonum
Nonpositive-Single-Flonum
Single-Flonum-Negative-Zero
Single-Flonum-Positive-Zero
Single-Flonum-Zero
Single-Flonum-Nan
Positive-Inexact-Real
Nonnegative-Inexact-Real
Negative-Inexact-Real
Nonpositive-Inexact-Real
Inexact-Real-Negative-Zero
Inexact-Real-Positive-Zero
Inexact-Real-Zero
Inexact-Real-Nan
Positive-Exact-Rational
Nonnegative-Exact-Rational
Negative-Exact-Rational
Nonpositive-Exact-Rational
Positive-Real
Nonnegative-Real
Negative-Real
Nonpositive-Real
Real-Zero
One
Byte
Positive-Byte
Index
Positive-Index
Fixnum
Positive-Fixnum
Nonnegative-Fixnum
Negative-Fixnum
Nonpositive-Fixnum
1.1.2`` Other Base Types
Boolean
True
False
String
Keyword
Symbol
Char
Void
Input-Port
Output-Port
Port
Path
Path-For-Some-System
Regexp
PRegexp
Byte-Regexp
Byte-PRegexp
Bytes
Namespace
Namespace-Anchor
Variable-Reference
Null
EOF
Continuation-Mark-Set
Undefined
Module-Path
Module-Path-Index
Resolved-Module-Path
Compiled-Module-Expression
Compiled-Expression
Internal-Definition-Context
Pretty-Print-Style-Table
Special-Comment
Struct-Type-Property
Impersonator-Property
Read-Table
Bytes-Converter
Parameterization
Custodian
Inspector
Security-Guard
UDP-Socket
TCP-Listener
Logger
Log-Receiver
Log-Level
Thread
Thread-Group
Subprocess
Place
Place-Channel
Semaphore
Will-Executor
Pseudo-Random-Generator
Path-String
1.2`` Singleton Types
1.3`` Containers
Pairof
Listof
List
List*
MListof
MPairof
Boxof
Vectorof
Vector
Fl Vector
Vector Top
Hash Table
Hash Table Top
Setof
Channelof
Parameterof
Promise
Futureof
Sequenceof
Custodian-Boxof
Thread-Cellof
Ephemeronof
1.4`` Syntax Objects
Syntaxof
Identifier
Syntax
Syntax-E
Sexpof
Sexp
Datum
1.5`` Control
Prompt-Tagof
Continuation-Mark-Keyof
1.6`` Other Type Constructors
->
Procedure
U
case->
All
Values
Rec
Struct
→
case→
∀
1.7`` Other Types
Option
Opaque

5.3.6
top ← prev up next →

### 1`` Type Reference

> > syntax

> > Any

Any Racket value. All other types are subtypes of Any.

> > syntax

> > Nothing

The empty type. No values inhabit this type, and any expression of this type will not evaluate to a value.

#### 1.1`` Base Types

##### 1.1.1`` Numeric Types

These types represent the hierarchy of numbers of Racket.

> > syntax

> > Number

> > syntax

> > Complex

Number and Complex are synonyms. This is the most general numeric type, including all Racket numbers, both exact and inexact, including complex numbers.

> > syntax

> > Integer

Includes Racket’s exact integers and corresponds to the exact-integer? predicate. This is the most general type that is still valid for indexing and other operations that require integral values.

> > syntax

> > Float

> > syntax

> > Flonum

Includes Racket’s double-precision (default) floating-point numbers and corresponds to the flonum? predicate. This type excludes single-precision floating-point numbers.

> > syntax

> > Single-Flonum

Includes Racket’s single-precision floating-point numbers and corresponds to the single-flonum? predicate. This type excludes double-precision floating-point numbers.

> > syntax

> > Inexact-Real

Includes all of Racket’s floating-point numbers, both single- and double-precision.

> > syntax

> > Exact-Rational

Includes Racket’s exact rationals, which include fractions and exact integers.

> > syntax

> > Real

Includes all of Racket’s real numbers, which include both exact rationals and all floating-point numbers. This is the most general type for which comparisons (e.g. <) are defined.

> > syntax

> > Exact-Number

> > syntax

> > Float-Complex

> > syntax

> > Single-Flonum-Complex

> > syntax

> > Inexact-Complex

These types correspond to Racket’s complex numbers.

The above types can be subdivided into more precise types if you want to enforce tighter constraints. Typed Racket provides types for the positive, negative, non-negative and non-positive subsets of the above types (where applicable).

> > syntax

> > Positive-Integer

> > syntax

> > Exact-Positive-Integer

> > syntax

> > Nonnegative-Integer

> > syntax

> > Exact-Nonnegative-Integer

> > syntax

> > Natural

> > syntax

> > Negative-Integer

> > syntax

> > Nonpositive-Integer

> > syntax

> > Zero

> > syntax

> > Positive-Float

> > syntax

> > Positive-Flonum

> > syntax

> > Nonnegative-Float

> > syntax

> > Nonnegative-Flonum

> > syntax

> > Negative-Float

> > syntax

> > Negative-Flonum

> > syntax

> > Nonpositive-Float

> > syntax

> > Nonpositive-Flonum

> > syntax

> > Float-Negative-Zero

> > syntax

> > Flonum-Negative-Zero

> > syntax

> > Float-Positive-Zero

> > syntax

> > Flonum-Positive-Zero

> > syntax

> > Float-Zero

> > syntax

> > Flonum-Zero

> > syntax

> > Float-Nan

> > syntax

> > Flonum-Nan

> > syntax

> > Positive-Single-Flonum

> > syntax

> > Nonnegative-Single-Flonum

> > syntax

> > Negative-Single-Flonum

> > syntax

> > Nonpositive-Single-Flonum

> > syntax

> > Single-Flonum-Negative-Zero

> > syntax

> > Single-Flonum-Positive-Zero

> > syntax

> > Single-Flonum-Zero

> > syntax

> > Single-Flonum-Nan

> > syntax

> > Positive-Inexact-Real

> > syntax

> > Nonnegative-Inexact-Real

> > syntax

> > Negative-Inexact-Real

> > syntax

> > Nonpositive-Inexact-Real

> > syntax

> > Inexact-Real-Negative-Zero

> > syntax

> > Inexact-Real-Positive-Zero

> > syntax

> > Inexact-Real-Zero

> > syntax

> > Inexact-Real-Nan

> > syntax

> > Positive-Exact-Rational

> > syntax

> > Nonnegative-Exact-Rational

> > syntax

> > Negative-Exact-Rational

> > syntax

> > Nonpositive-Exact-Rational

> > syntax

> > Positive-Real

> > syntax

> > Nonnegative-Real

> > syntax

> > Negative-Real

> > syntax

> > Nonpositive-Real

> > syntax

> > Real-Zero

Natural and Exact-Nonnegative-Integer are synonyms. So are the integer and exact-integer types, and the float and flonum types. Zero includes only the integer 0. Real-Zero includes exact 0 and all the floating-point zeroes.

These types are useful when enforcing that values have a specific sign. However, programs using them may require additional dynamic checks when the type-checker cannot guarantee that the sign constraints will be respected.

In addition to being divided by sign, integers are further subdivided into range-bounded types.

> > syntax

> > One

> > syntax

> > Byte

> > syntax

> > Positive-Byte

> > syntax

> > Index

> > syntax

> > Positive-Index

> > syntax

> > Fixnum

> > syntax

> > Positive-Fixnum

> > syntax

> > Nonnegative-Fixnum

> > syntax

> > Negative-Fixnum

> > syntax

> > Nonpositive-Fixnum

One includes only the integer 1. Byte includes numbers from 0 to 255. Index is bounded by 0 and by the length of the longest possible Racket vector. Fixnum includes all numbers represented by Racket as machine integers. For the latter two families, the sets of values included in the types are architecture-dependent, but typechecking is architecture-independent.

These types are useful to enforce bounds on numeric values, but given the limited amount of closure properties these types offer, dynamic checks may be needed to check the desired bounds at runtime.

Examples:

> > 7
> - : Integer [generalized from Positive-Byte]
> 7
> > 8.3
> - : Flonum [generalized from Positive-Flonum]
> 8.3
> > (/ 8 3)
> - : Exact-Rational [generalized from Positive-Exact-Rational]
> 8/3
> > 0
> - : Integer [generalized from Zero]
> 0
> > -12
> - : Integer [generalized from Negative-Fixnum]
> -12
> > 3+4i
> - : Exact-Number
> 3+4i

##### 1.1.2`` Other Base Types

> > syntax

> > Boolean

> > syntax

> > True

> > syntax

> > False

> > syntax

> > String

> > syntax

> > Keyword

> > syntax

> > Symbol

> > syntax

> > Char

> > syntax

> > Void

> > syntax

> > Input-Port

> > syntax

> > Output-Port

> > syntax

> > Port

> > syntax

> > Path

> > syntax

> > Path-For-Some-System

> > syntax

> > Regexp

> > syntax

> > PRegexp

> > syntax

> > Byte-Regexp

> > syntax

> > Byte-PRegexp

> > syntax

> > Bytes

> > syntax

> > Namespace

> > syntax

> > Namespace-Anchor

> > syntax

> > Variable-Reference

> > syntax

> > Null

> > syntax

> > EOF

> > syntax

> > Continuation-Mark-Set

> > syntax

> > Undefined

> > syntax

> > Module-Path

> > syntax

> > Module-Path-Index

> > syntax

> > Resolved-Module-Path

> > syntax

> > Compiled-Module-Expression

> > syntax

> > Compiled-Expression

> > syntax

> > Internal-Definition-Context

> > syntax

> > Pretty-Print-Style-Table

> > syntax

> > Special-Comment

> > syntax

> > Struct-Type-Property

> > syntax

> > Impersonator-Property

> > syntax

> > Read-Table

> > syntax

> > Bytes-Converter

> > syntax

> > Parameterization

> > syntax

> > Custodian

> > syntax

> > Inspector

> > syntax

> > Security-Guard

> > syntax

> > UDP-Socket

> > syntax

> > TCP-Listener

> > syntax

> > Logger

> > syntax

> > Log-Receiver

> > syntax

> > Log-Level

> > syntax

> > Thread

> > syntax

> > Thread-Group

> > syntax

> > Subprocess

> > syntax

> > Place

> > syntax

> > Place-Channel

> > syntax

> > Semaphore

> > syntax

> > Will-Executor

> > syntax

> > Pseudo-Random-Generator

These types represent primitive Racket data.

Examples:

> > #t
> - : Boolean [generalized from True]
> #t
> > #f
> - : False
> #f
> > "hello"
> - : String
> "hello"
> > (current-input-port)
> - : Input-Port
> #<input-port:string>
> > (current-output-port)
> - : Output-Port
> #<output-port:string>
> > (string->path "/")
> - : Path
> #<path:/>
> > #rx"a*b*"
> - : Regexp
> #rx"a*b*"
> > #px"a*b*"
> - : PRegexp
> #px"a*b*"
> > '#"bytes"
> - : Bytes
> #"bytes"
> > (current-namespace)
> - : Namespace
> #<namespace:0>
> > #\b
> - : Char
> #\b
> > (thread (lambda () (add1 7)))
> - : Thread
> #<thread>

> > syntax

> > Path-String

The union of the Path and String types. Note that this does not match exactly what the predicate path-string? recognizes. For example, strings that contain the character #\nul have the type Path-String but path-string? returns #f for those strings. For a complete specification of which strings path-string? accepts, see its documentation.

#### 1.2`` Singleton Types

Some kinds of data are given singleton types by default. In particular, booleans, symbols, and keywords have types which consist only of the particular boolean, symbol, or keyword. These types are subtypes of Boolean, Symbol and Keyword, respectively.

Examples:

> > #t
> - : Boolean [generalized from True]
> #t
> > '#:foo
> - : #:foo
> '#:foo
> > 'bar
> - : Symbol [generalized from 'bar]
> 'bar

#### 1.3`` Containers

The following base types are parameteric in their type arguments.

> > syntax

> > (Pairof s t)

is the pair containing s as the car and t as the cdr

Examples:

> > (cons 1 2)
> - : (Pairof One Positive-Byte)
> '(1 . 2)
> > (cons 1 "one")
> - : (Pairof One String)
> '(1 . "one")

> > syntax

> > (Listof t)

Homogenous lists of t

> > syntax

> > (List t ...)

is the type of the list with one element, in order, for each type provided to the List type constructor.

> > syntax

> > (List t ... trest ... bound)

is the type of a list with one element for each of the ts, plus a sequence of elements corresponding to trest, where bound must be an identifier denoting a type variable bound with ....

> > syntax

> > (List* t t1 ... s)

is equivalent to (Pairof t (List* t1 ... s)).

Examples:

> > (list 'a 'b 'c)
> - : (Listof (U 'a 'b 'c)) [generalized from (List 'a 'b 'c)]
> '(a b c)

> > (plambda: (a ...) ([sym : Symbol] boxes : (Boxof a) ... a)
> (ann (cons sym boxes) (List Symbol (Boxof a) ... a)))

> - : (All (a ...) (Symbol (Boxof a) ... a -> (Pairof Symbol (List (Boxof a) ... a))))
> #<procedure>
> > (map symbol->string (list 'a 'b 'c))
> - : (Listof String) [generalized from (Pairof String (Listof String))]
> '("a" "b" "c")

> > syntax

> > (MListof t)

Homogenous mutable lists of t.

> > syntax

> > (MPairof t u)

Mutable pairs of t and u.

> > syntax

> > (Boxof t)

A box of t

Example:

> > (box "hello world")
> - : (Boxof String)
> '#&"hello world"

> > syntax

> > (Vectorof t)

Homogenous vectors of t

> > syntax

> > (Vector t ...)

is the type of the list with one element, in order, for each type provided to the Vector type constructor.

> > syntax

> > FlVector

An flvector.

Examples:

> > (vector 1 2 3)
> - : (Vector Integer Integer Integer)
> '#(1 2 3)
> > #(a b c)
> - : (Vector Symbol Symbol Symbol)
> '#(a b c)

> > syntax

> > VectorTop

is the type of a vector with unknown length and element types. Only read-only vector operations (e.g. vector-ref) are allowed on values of this type. This type typically appears in programs via the combination of occurrence typing and vector?.

Example:

> > (lambda: ([x : Any]) (if (vector? x) x (error "not a vector!")))
> - : (Any -> VectorTop : ((OrFilter (! False @ 0) (! VectorTop @ 0)) | (! VectorTop @ 0)))
> #<procedure>

> > syntax

> > (HashTable k v)

is the type of a hash table with key type k and value type v.

Example:

> > #hash((a . 1) (b . 2))
> - : (HashTable Symbol Integer)
> '#hash((a . 1) (b . 2))

> > syntax

> > HashTableTop

is the type of a hash table with unknown key and value types. Only read-only hash table operations (e.g. hash-ref) are allowed on values of this type. This type typically appears in programs via the combination of occurrence typing and hash?.

Example:

> > (lambda: ([x : Any]) (if (hash? x) x (error "not a hash table!")))
> - : (Any -> HashTableTop : ((OrFilter (! False @ 0) (! HashTableTop @ 0)) | (! HashTableTop @ 0)))
> #<procedure>

> > syntax

> > (Setof t)

is the type of a set of t.

Example:

> > (set 0 1 2 3)
> - : (Setof Byte)
> (set 0 1 2 3)

> > syntax

> > (Channelof t)

A channel on which only ts can be sent.

Example:

> > (ann (make-channel) (Channelof Symbol))
> - : (Channelof Symbol)
> #<channel>

> > syntax

> > (Parameterof t)

> (Parameterof s t)

A parameter of t. If two type arguments are supplied, the first is the type the parameter accepts, and the second is the type returned.

Examples:

> > current-input-port
> - : (Parameterof Input-Port)
> #<procedure:current-input-port>
> > current-directory
> - : (Parameterof Path-String Path)
> #<procedure:current-directory>

> > syntax

> > (Promise t)

A promise of t.

Example:

> > (delay 3)
> - : (Promise Positive-Byte)
> #<promise:eval:38:0>

> > syntax

> > (Futureof t)

A future which produce a value of type t when touched.

> > syntax

> > (Sequenceof t)

A sequence that produces values of type t on each iteration.

> > syntax

> > (Custodian-Boxof t)

A custodian box of t.

> > syntax

> > (Thread-Cellof t)

A thread cell of t.

> > syntax

> > (Ephemeronof t)

An ephemeron whose value is of type t.

#### 1.4`` Syntax Objects

The following types represent syntax objects and their content.

> > syntax

> > (Syntaxof t)

A syntax object with content of type t. Applying syntax-e to a value of type (Syntaxof t) produces a value of type t.

> > syntax

> > Identifier

A syntax object containing a symbol. Equivalent to (Syntaxof Symbol).

> > syntax

> > Syntax

A syntax object containing only symbols, keywords, strings, characters, booleans, numbers, boxes containing Syntax, vectors of Syntax, or (possibly improper) lists of Syntax. Equivalent to (Syntaxof Syntax-E).

> > syntax

> > Syntax-E

The content of syntax objects of type Syntax. Applying syntax-e to a value of type Syntax produces a value of type Syntax-E.

> > syntax

> > (Sexpof t)

The recursive union of t with symbols, keywords, strings, characters, booleans, numbers, boxes, vectors, and (possibly improper) lists.

> > syntax

> > Sexp

Applying syntax->datum to a value of type Syntax produces a value of type Sexp. Equivalent to (Sexpof Nothing).

> > syntax

> > Datum

Applying datum->syntax to a value of type Datum produces a value of type Syntax. Equivalent to (Sexpof Syntax).

#### 1.5`` Control

The following types represent prompt tags and keys for continuation marks for use with delimited continuation functions and continuation mark functions.

> > syntax

> > (Prompt-Tagof s t)

A prompt tag to be used in a continuation prompt whose body produces the type s and whose handler has the type t. The type t must be a function type.

The domain of t determines the type of the values that can be aborted, using abort-current-continuation, to a prompt with this prompt tag.

Example:

> > (make-continuation-prompt-tag 'prompt-tag)
> - : (Prompt-Tagof Integer Integer)
> #<continuation-prompt-tag:prompt-tag>

> > syntax

> > (Continuation-Mark-Keyof t)

A continuation mark key that is used for continuation mark operations such as with-continuation-mark and continuation-mark-set->list. The type t represents the type of the data that is stored in the continuation mark with this key.

Example:

> > (make-continuation-mark-key 'mark-key)
> - : (Continuation-Mark-Keyof Integer)
> #<continuation-mark-key>

#### 1.6`` Other Type Constructors

> > syntax

> > (dom ... -> rng)

> (dom ... rest * -> rng)
> (dom ... rest ooo bound -> rng)
> (dom -> rng : pred)

> ooo |  | = |  | ...
> dom |  | = |  | type
> |  | | |  | keyword type
> |  | | |  | [keyword type]

The type of functions from the (possibly-empty) sequence dom ... to the rng type. The second form specifies a uniform rest argument of type rest, and the third form specifies a non-uniform rest argument of type rest with bound bound. In the third form, the ... introduced by ooo is literal, and bound must be an identifier denoting a type variable. In the fourth form, there must be only one dom and pred is the type checked by the predicate. dom can include both mandatory and optional keyword arguments.

Examples:

> > (λ: ([x : Number]) x)
> - : (Number -> Number : ((! False @ 0) | (False @ 0)) (0))
> #<procedure>
> > (λ: ([x : Number] y : String *) (length y))
> - : (Number String * -> Index)
> #<procedure>
> > ormap
> - : (All (a c b ...) ((a b ... b -> c) (Listof a) (Listof b) ... b -> (U False c)))
> #<procedure:ormap>
> > string?
> - : (Any -> Boolean : String)
> #<procedure:string?>
> > (:print-type file->string)
> (Path-String [#:mode (U 'binary 'text)] -> String)

> > (: is-zero? : Number #:equality (Number Number -> Any) [#:zero Number] -> Any)

> > (define (is-zero? n #:equality equality #:zero [zero 0])
> (equality n zero))

> > (is-zero? 2 #:equality =)
> - : Any
> #f
> > (is-zero? 2 #:equality eq? #:zero 2.0)
> - : Any
> #f

> > syntax

> > Procedure

is the supertype of all function types.

> > syntax

> > (U t ...)

is the union of the types t ....

Example:

> > (λ: ([x : Real])(if (> 0 x) "yes" 'no))
> - : (Real -> (U String 'no) : ((Real @ 0) | Bot))
> #<procedure>

> > syntax

> > (case-> fun-ty ...)

is a function that behaves like all of the fun-tys, considered in order from first to last. The fun-tys must all be function types constructed with ->.

Example:

> > (: add-map : (case->
> [(Listof Integer) -> (Listof Integer)]
> [(Listof Integer) (Listof Integer) -> (Listof Integer)]))

For the definition of add-map look into case-lambda:.

> > syntax

> > (t t1 t2 ...)

is the instantiation of the parametric type t at types t1 t2 ...

> > syntax

> > (All (a ...) t)

> (All (a ... a ooo) t)

is a parameterization of type t, with type variables v .... If t is a function type constructed with ->, the outer pair of parentheses around the function type may be omitted.

Examples:

> > (: list-length : (All (A) (Listof A) -> Natural))

> > (define (list-length lst)
> (if (null? lst)
> 0
> (add1 (list-length (cdr lst)))))

> > (list-length (list 1 2 3))
> - : Integer [generalized from Nonnegative-Integer]
> 3

> > syntax

> > (Values t ...)

is the type of a sequence of multiple values, with types t .... This can only appear as the return type of a function.

Example:

> > (values 1 2 3)
> - : (Values Integer Integer Integer) [generalized from (Values One Positive-Byte Positive-Byte)]

> 1
> 2
> 3

> > syntax

> > v

where v is a number, boolean or string, is the singleton type containing only that value

> > syntax

> > (quote val)

where val is a Racket value, is the singleton type containing only that value

> > syntax

> > i

where i is an identifier can be a reference to a type name or a type variable

> > syntax

> > (Rec n t)

is a recursive type where n is bound to the recursive type in the body t

Examples:

> > (define-type IntList (Rec List (Pair Integer (U List Null))))

> > (define-type (List A) (Rec List (Pair A (U List Null))))

> > syntax

> > (Struct st)

is a type which is a supertype of all instances of the potentially-polymorphic structure type st. Note that structure accessors for st will not accept (Struct st) as an argument.

> > syntax

> > →

An alias for ->.

> > syntax

> > case→

An alias for case->.

> > syntax

> > ∀

An alias for All.

#### 1.7`` Other Types

> > syntax

> > (Option t)

Either t or #f

> > syntax

> > (Opaque t)

A type constructed using the #:opaque clause of require/typed.
top ← prev up next →