Version: 5.1.2
1 Type Reference
Any Racket value. All other types are subtypes of
Any.
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
Examples: |
> 7 | - : Positive-Byte | 7 | > 8.3 | - : Positive-Flonum | 8.3 | > (/ 8 3) | - : Positive-Exact-Rational | 8/3 | > 0 | - : Zero | 0 | > -12 | - : Negative-Fixnum | -12 | > 3+4i | - : Exact-Number | 3+4i |
|
1.1.2 Other Base Types
These types represent primitive Racket data.
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 | - : True | #t | > '#:foo | - : #:foo | '#:foo | > 'bar | - : 'bar | 'bar |
|
1.3 Containers
The following base types are parameteric in their type arguments.
is the
pair containing
s as the
car
and
t as the
cdrExamples: |
> (cons 1 2) | - : (Pairof One Positive-Byte) | '(1 . 2) | > (cons 1 "one") | - : (Pairof One String) | '(1 . "one") |
|
is the type of the list with one element, in order,
for each type provided to the
List type constructor.
(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
....
Examples: |
> (list 'a 'b 'c) | - : (List 'a 'b 'c) | '(a b c) | > (map symbol->string (list 'a 'b 'c)) | - : (Pairof String (Listof String)) | '("a" "b" "c") |
|
Example: |
> (box "hello world") | - : (Boxof String) | '#&"hello world" |
|
is the type of the list with one element, in order,
for each type provided to the
Vector type constructor.
Examples: |
> (vector 1 2 3) | - : (Vector Integer Integer Integer) | '#(1 2 3) | > #(a b c) | - : (Vector Symbol Symbol Symbol) | '#(a b c) |
|
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((b . 2) (a . 1)) |
|
is the type of a
set of
t.
Example: |
> (set 0 1 2 3) | - : (Setof Byte) | #<set: 0 1 2 3> |
|
A
channel on which only
ts can be sent.
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.
Example: |
> (delay 3) | - : (Promise Positive-Byte) | #<promise:eval:35:0> |
|
A
future which produce a value of type
t when touched.
A
sequence that produces values of the
types
t ... on each iteration.
1.4 Syntax Objects
The following types represent syntax objects and their content.
A syntax object with content of type
t.
Applying
syntax-e to a value of type
(Syntaxof t) produces a
value of type
t.
1.5 Other Type Constructors
(dom ... -> rng) |
(dom ... rest * -> rng) |
(dom ... rest ... bound -> rng) |
(dom -> rng : pred) |
is 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
second occurrence of
... 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.
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 -> c)) | #<procedure:ormap> | > string? | - : (Any -> Boolean : String) | #<procedure:string?> |
|
is the supertype of all function types.
is the union of the types
t ....
Example: |
> (λ: ([x : Real])(if (> 0 x) "yes" 'no)) | - : (Real -> (U String 'no) : (Top | Bot)) | #<procedure> |
|
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
->.
is the instantiation of the parametric type
t at types
t1 t2 ...
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.
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 One Positive-Byte Positive-Byte) | 1 | 2 | 3 |
|
where v is a number, boolean or string, is the singleton type containing only that value
where val is a Racket value, is the singleton type containing only that value
where i is an identifier can be a reference to a type
name or a type variable
is a recursive type where n is bound to the
recursive type in the body t
1.6 Other Types
Either t or #f
A type constructed using require-opaque-type.