This file is indexed.

/usr/share/doc/racket/ts-guide/optimization.html is in racket-doc 6.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><title>7&nbsp;Optimization in Typed Racket</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_0&quot;);">&#9660;</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">The Typed Racket Guide</a></td></tr></table></div><div class="tocviewsublisttop" style="display: block;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="quick.html" class="tocviewlink" data-pltdoc="x">Quick Start</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="beginning.html" class="tocviewlink" data-pltdoc="x">Beginning Typed Racket</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="more.html" class="tocviewlink" data-pltdoc="x">Specifying Types</a></td></tr><tr><td align="right">4&nbsp;</td><td><a href="types.html" class="tocviewlink" data-pltdoc="x">Types in Typed Racket</a></td></tr><tr><td align="right">5&nbsp;</td><td><a href="occurrence-typing.html" class="tocviewlink" data-pltdoc="x">Occurrence Typing</a></td></tr><tr><td align="right">6&nbsp;</td><td><a href="typed-untyped-interaction.html" class="tocviewlink" data-pltdoc="x">Typed-<wbr></wbr>Untyped Interaction</a></td></tr><tr><td align="right">7&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">Optimization in Typed Racket</a></td></tr><tr><td align="right">8&nbsp;</td><td><a href="caveats.html" class="tocviewlink" data-pltdoc="x">Caveats and Limitations</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_1&quot;);">&#9658;</a></td><td>7&nbsp;</td><td><a href="" class="tocviewselflink" data-pltdoc="x">Optimization in Typed Racket</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">7.1&nbsp;</td><td><a href="#%28part._.Turning_the_optimizer_off%29" class="tocviewlink" data-pltdoc="x">Turning the optimizer off</a></td></tr><tr><td align="right">7.2&nbsp;</td><td><a href="#%28part._.Getting_the_most_out_of_the_optimizer%29" class="tocviewlink" data-pltdoc="x">Getting the most out of the optimizer</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">7.1<tt>&nbsp;</tt></span><a href="#%28part._.Turning_the_optimizer_off%29" class="tocsubseclink" data-pltdoc="x">Turning the optimizer off</a></td></tr><tr><td><span class="tocsublinknumber">7.2<tt>&nbsp;</tt></span><a href="#%28part._.Getting_the_most_out_of_the_optimizer%29" class="tocsubseclink" data-pltdoc="x">Getting the most out of the optimizer</a></td></tr><tr><td><span class="tocsublinknumber">7.2.1<tt>&nbsp;</tt></span><a href="#%28part._.Numeric_types%29" class="tocsubseclink" data-pltdoc="x">Numeric types</a></td></tr><tr><td><span class="tocsublinknumber">7.2.2<tt>&nbsp;</tt></span><a href="#%28part._.Lists%29" class="tocsubseclink" data-pltdoc="x">Lists</a></td></tr><tr><td><span class="tocsublinknumber">7.2.3<tt>&nbsp;</tt></span><a href="#%28part._.Vectors%29" class="tocsubseclink" data-pltdoc="x">Vectors</a></td></tr><tr><td><span class="tocsublinknumber">7.2.4<tt>&nbsp;</tt></span><a href="#%28part._contract-costs%29" class="tocsubseclink" data-pltdoc="x">Contract boundaries</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="versionbox"><span class="version">6.3</span></div><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;6.3&quot;, &quot;../&quot;);" onfocus="this.style.color=&quot;black&quot;; this.style.textAlign=&quot;left&quot;; if (this.value == &quot;...search manuals...&quot;) this.value=&quot;&quot;;" onblur="if (this.value.match(/^ *$/)) { this.style.color=&quot;#888&quot;; this.style.textAlign=&quot;center&quot;; this.value=&quot;...search manuals...&quot;; }"/></form>&nbsp;&nbsp;<a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;6.3&quot;);">top</a></span><span class="navright">&nbsp;&nbsp;<a href="typed-untyped-interaction.html" title="backward to &quot;6 Typed-Untyped Interaction&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="index.html" title="up to &quot;The Typed Racket Guide&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="caveats.html" title="forward to &quot;8 Caveats and Limitations&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div><h3 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;optimization&quot;">7<tt>&nbsp;</tt><a name="(part._optimization)"></a>Optimization in Typed Racket</h3><blockquote class="refpara"><blockquote class="refcolumn"><blockquote class="refcontent"><p>For general information on Racket performance and
benchmarking, see <a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=guide&amp;rel=performance.html&amp;version=6.3" class="Sq" data-pltdoc="x">Performance</a>.</p></blockquote></blockquote></blockquote><p>Typed Racket provides a type-driven optimizer that rewrites well-typed
programs to potentially make them faster. It should in no way make
your programs slower or unsafe.</p><h4 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;Turning_the_optimizer_off&quot;">7.1<tt>&nbsp;</tt><a name="(part._.Turning_the_optimizer_off)"></a>Turning the optimizer off</h4><p>Typed Racket&rsquo;s optimizer is turned on by default. If you want to
deactivate it (for debugging, for instance), you must add the
<a name="(idx._(gentag._1._(lib._typed-racket/scribblings/ts-guide..scrbl)))"></a><span class="RktPn">#:no-optimize</span> keyword when specifying the language of your
program:</p><blockquote class="SCodeFlow"><p><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=guide&amp;rel=Module_Syntax.html%23%2528part._hash-lang%2529&amp;version=6.3" class="RktModLink Sq" data-pltdoc="x"><span class="RktMod">#lang</span></a><span class="hspace">&nbsp;</span><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=index.html&amp;version=6.3" class="RktModLink Sq" data-pltdoc="x"><span class="RktSym">typed/racket</span></a><span class="hspace">&nbsp;</span><span class="RktPn">#:no-optimize</span></p></blockquote><h4 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;Getting_the_most_out_of_the_optimizer&quot;">7.2<tt>&nbsp;</tt><a name="(part._.Getting_the_most_out_of_the_optimizer)"></a>Getting the most out of the optimizer</h4><p>Typed Racket&rsquo;s optimizer can improve the performance of various common
Racket idioms. However, it does a better job on some idioms than on
others. By writing your programs using the right idioms, you can help
the optimizer help you.</p><p>To best take advantage of the Typed Racket optimizer, keep the following in
mind. The <span style="font-style: italic">Optimization Coach</span> package provides optimization coaching
support to help you in this task.</p><h5 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;Numeric_types&quot;">7.2.1<tt>&nbsp;</tt><a name="(part._.Numeric_types)"></a>Numeric types</h5><p>Being type-driven, the optimizer makes most of its decisions based on
the types you assigned to your data. As such, you can improve the
optimizer&rsquo;s usefulness by writing informative types.</p><p><div class="SIntrapara">For example, the following programs both typecheck:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Real%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Real</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Real%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Real</a></span><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">+</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">2.5</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktVal">3.5</span><span class="RktPn">)</span></td></tr></table></blockquote></div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">+</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">2.5</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym">f</span><span class="hspace">&nbsp;</span><span class="RktVal">3.5</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><p>However, the second one uses more informative types: the
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span> type includes only 64-bit floating-point numbers
whereas the
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Real%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Real</a></span> type includes both exact and
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._inexact._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">inexact</span></a>
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._real._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">real numbers</span></a>
and the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Inexact-.Real%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Inexact-Real</a></span> type includes both 32- and 64-bit
floating-point numbers.
Typed Racket&rsquo;s optimizer can optimize the latter program to use
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._inexact._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">float</span></a>
-specific operations whereas it cannot do anything with the
former program.</p><p>Thus, to get the most of Typed Racket&rsquo;s optimizer, you should use the
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span> type when possible. For similar reasons, you should use
floating-point literals instead of exact literals when doing
floating-point computations.</p><p>When mixing floating-point numbers and exact reals in arithmetic
operations, the result is not necessarily a <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span>. For
instance, the result of <span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252A%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">*</a></span><span class="stt"> </span><span class="RktVal">2.0</span><span class="stt"> </span><span class="RktVal">0</span><span class="RktPn">)</span> is <span class="RktVal">0</span> which is not
a <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float</a></span>. This can result in missed optimizations. To prevent
this, when mixing floating-point numbers and exact reals, coerce exact
reals to floating-point numbers using <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=number-types.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._exact-%7E3einexact%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">exact-&gt;inexact</a></span>. This is
not necessary when using <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">+</a></span> or <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._-%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x"><span class="nobreak">-</span></a></span>. When mixing
floating-point numbers of different precisions, results use the
highest precision possible.</p><p>On a similar note, the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float-.Complex%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float-Complex</a></span> type is preferable to
the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Complex%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Complex</a></span> type for the same reason. Typed Racket can keep
float
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._complex._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">complex numbers</span></a>
unboxed; as such, programs using
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._complex._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">complex numbers</span></a>
can have better performance than equivalent programs that
represent
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._complex._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">complex numbers</span></a>
as two
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._real._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">real numbers</span></a>.
As with floating-point literals, float
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._complex._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">complex</span></a>
literals (such as <span class="RktVal">1.0+1.0i</span>) should be preferred over exact
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._complex._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">complex</span></a>
literals (such as <span class="RktVal">1+1i</span>). Note that both parts of a literal must be
present and
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=numbers.html%23%2528tech._inexact._number%2529&amp;version=6.3" class="techoutside Sq" data-pltdoc="x"><span class="techinside">inexact</span></a>
for the literal to be of type
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float-.Complex%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float-Complex</a></span>; <span class="RktVal">0.0+1.0i</span> is of type
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Float-.Complex%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Float-Complex</a></span> but <span class="RktVal">0+1.0i</span> is not.
To get the most of
Typed Racket&rsquo;s optimizer, you should also favor rectangular
coordinates over polar coordinates.</p><h5 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;Lists&quot;">7.2.2<tt>&nbsp;</tt><a name="(part._.Lists)"></a>Lists</h5><p>Typed Racket handles potentially empty lists and lists that are known
to be non-empty differently: when taking the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span> or the
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span> of a list Typed Racket knows is non-empty, it can skip
the check for the empty list that is usually done when calling
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span> and <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span>.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sum</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">l</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Listof%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Listof</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="RktPn">)</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=if.html%23%2528form._%2528%2528quote._%7E23%7E25kernel%2529._if%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">if</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._null%7E3f%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">null?</a></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktVal">0</span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">+</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sum</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote><p>In this example, Typed Racket knows that if we reach the else branch,
<span class="RktSym">l</span> is not empty. The checks associated with <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span> and
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span> would be redundant and are eliminated.</p><p>In addition to explicitly checking for the empty list using
<span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._null%7E3f%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">null?</a></span>, you can inform Typed Racket that a list is non-empty
by using the known-length list type constructor; if your data is
stored in lists of fixed length, you can use the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types-extra..rkt%2529._.List%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">List</a></span> type
constructors.</p><p><div class="SIntrapara">For instance, the type of a list of two <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span>s can be
written either as:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed%252Fracket%252Fbase..rkt%2529._define-type%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define-type</a></span><span class="hspace">&nbsp;</span><span class="RktSym">List-2-Ints</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Listof%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Listof</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="RktPn">)</span><span class="RktPn">)</span></p></blockquote></div><div class="SIntrapara">or as the more precise:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><p><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed%252Fracket%252Fbase..rkt%2529._define-type%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define-type</a></span><span class="hspace">&nbsp;</span><span class="RktSym">List-2-Ints</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types-extra..rkt%2529._.List%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">List</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="RktPn">)</span><span class="RktPn">)</span></p></blockquote></div></p><p><div class="SIntrapara">Using the second definition, all <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span> and <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span>-related
checks can be eliminated in this function:
</div><div class="SIntrapara"><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym">sum2</span><span class="hspace">&nbsp;</span><span class="RktPn">[</span><span class="RktSym">l</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym">List-2-Ints</span><span class="RktPn">]</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span></td></tr><tr><td><span class="hspace">&nbsp;&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252B%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">+</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span><span class="hspace">&nbsp;</span><span class="RktSym">l</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr></table></blockquote></div></p><h5 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;Vectors&quot;">7.2.3<tt>&nbsp;</tt><a name="(part._.Vectors)"></a>Vectors</h5><p>In addition to known-length lists, Typed Racket supports known-length
vectors through the <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types-extra..rkt%2529._.Vector%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Vector</a></span> type constructor. Known-length
vector access using constant indices can be optimized in a similar
fashion as <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._car%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">car</a></span> and <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=pairs.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._cdr%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">cdr</a></span>.</p><blockquote class="SCodeFlow"><table cellspacing="0" cellpadding="0" class="RktBlk"><tr><td><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">#(color r g b)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed%252Fracket%252Fbase..rkt%2529._define-type%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define-type</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Color</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types-extra..rkt%2529._.Vector%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Vector</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.String%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">String</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=type-ref.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fbase-types..rkt%2529._.Integer%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">Integer</a></span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._%7E3a%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">:</a></span><span class="hspace">&nbsp;</span><span class="RktSym">Color</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=vectors.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._vector%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">vector</a></span><span class="hspace">&nbsp;</span><span class="RktVal">"red"</span><span class="hspace">&nbsp;</span><span class="RktVal">255</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=vectors.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._vector-ref%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">vector-ref</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">good</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._define%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">define</a></span><span class="hspace">&nbsp;</span><span class="RktSym">color-name</span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="RktPn">)</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=vectors.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._vector-ref%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">vector-ref</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktSym">color-name</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">good</span></td></tr><tr><td><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=vectors.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._vector-ref%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">vector-ref</a></span><span class="hspace">&nbsp;</span><span class="RktSym">x</span><span class="hspace">&nbsp;</span><span class="RktPn">(</span><span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=reference&amp;rel=generic-numbers.html%23%2528def._%2528%2528quote._%7E23%7E25kernel%2529._%252A%2529%2529&amp;version=6.3" class="RktValLink Sq" data-pltdoc="x">*</a></span><span class="hspace">&nbsp;</span><span class="RktVal">0</span><span class="hspace">&nbsp;</span><span class="RktVal">10</span><span class="RktPn">)</span><span class="RktPn">)</span><span class="hspace">&nbsp;</span><span class="RktCmt">;</span><span class="RktCmt">&nbsp;</span><span class="RktCmt">bad</span></td></tr></table></blockquote><p>In many such cases, however, <a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=guide&amp;rel=define-struct.html&amp;version=6.3" class="Sq" data-pltdoc="x">structs</a> are
preferable to vectors. Typed Racket can optimize struct access in all
cases.</p><h5 x-source-module="(lib &quot;typed-racket/scribblings/ts-guide.scrbl&quot;)" x-source-pkg="typed-racket-doc" x-part-tag="&quot;contract-costs&quot;">7.2.4<tt>&nbsp;</tt><a name="(part._contract-costs)"></a>Contract boundaries</h5><p>When interoperating with untyped code (see <a href="typed-untyped-interaction.html" data-pltdoc="x">Typed-Untyped Interaction</a>),
contracts are installed between typed and untyped modules. Contracts can have
significant overhead, thus typed-untyped boundary crossings should be avoided
in performance-sensitive code.</p><p>Typed Racket provides types for most of the bindings provided by <span class="stt">#lang
racket</span>; using <span class="RktSym"><a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?doc=ts-reference&amp;rel=special-forms.html%23%2528form._%2528%2528lib._typed-racket%252Fbase-env%252Fprims..rkt%2529._require%252Ftyped%2529%2529&amp;version=6.3" class="RktStxLink Sq" data-pltdoc="x">require/typed</a></span> is unnecessary in these cases.</p><p>If you suspect that contracts at a typed-untyped boundary may be have a
significant cost in your program, you can investigate further using the
<a href="http://download.racket-lang.org/docs/6.3/html/local-redirect/index.html?tag=%28part._%28.%27%28lib._contract-profile%2Fscribblings%2Fcontract-profile..scrbl%29.%27._.%27top.%27%29%29&amp;version=6.3" class="Sq" data-pltdoc="x">contract profiler</a>.</p><p>If the contract profiler is not already installed, the following command
will install it:</p><p><span class="hspace">&nbsp;&nbsp;</span><span class="stt">raco pkg install contract-profile</span></p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" style="color: #888;" type="text" value="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;6.3&quot;, &quot;../&quot;);" onfocus="this.style.color=&quot;black&quot;; this.style.textAlign=&quot;left&quot;; if (this.value == &quot;...search manuals...&quot;) this.value=&quot;&quot;;" onblur="if (this.value.match(/^ *$/)) { this.style.color=&quot;#888&quot;; this.style.textAlign=&quot;center&quot;; this.value=&quot;...search manuals...&quot;; }"/></form>&nbsp;&nbsp;<a href="../index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;6.3&quot;);">top</a></span><span class="navright">&nbsp;&nbsp;<a href="typed-untyped-interaction.html" title="backward to &quot;6 Typed-Untyped Interaction&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="index.html" title="up to &quot;The Typed Racket Guide&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="caveats.html" title="forward to &quot;8 Caveats and Limitations&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div></div></div><div id="contextindicator">&nbsp;</div></body></html>