Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 52a37fb77746ef557a2ec666070d732e > files > 30

bigloo-doc-3.2b-3.fc12.i686.rpm

<!-- 95% W3C COMPLIANT, 95% CSS FREE, RAW HTML -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title>BiglooA ``practical Scheme compiler''User manual for version 3.2bJune 2009</title>
 <style type="text/css">
  <!--
  pre { font-family: monospace }
  tt { font-family: monospace }
  code { font-family: monospace }
  p.flushright { text-align: right }
  p.flushleft { text-align: left }
  span.sc { font-variant: small-caps }
  span.sf { font-family: sans-serif }
  span.skribetitle { font-family: sans-serif; font-weight: bolder; font-size: x-large; }
  span.refscreen { }
  span.refprint { display: none; }
  -->
 </style>
</head>

<body class="chapter" bgcolor="#ffffff">
<table width="100%" class="skribetitle" cellspacing="0" cellpadding="0"><tbody>
<tr><td align="center" bgcolor="#8381de"><div class="skribetitle"><strong><big><big><big>24. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Explicit typing</big></big></big></strong></div><center>
</center>
</td></tr></tbody></table>
<table cellpadding="3" cellspacing="0" width="100%" class="skribe-margins"><tr>
<td align="left" valign="top" class="skribe-left-margin" width="20%" bgcolor="#dedeff"><div class="skribe-left-margin">
<br/><center id='center30135'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30125" align="center" colspan="1"><font color="#ffffff"><strong id='bold30123'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30132" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc30128" align="left" valign="top" colspan="1"><strong id='bold30127'
>top:</strong></td><td id="tc30129" align="right" valign="top" colspan="1"><a href="bigloo.html#Bigloo-A-``practical-Scheme-compiler''-User-manual-for-version-3.2b-June-2009" class="inbound">Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009</a></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center30145'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30139" align="center" colspan="1"><font color="#ffffff"><strong id='bold30137'
>Explicit typing</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30142" align="center" colspan="1"></td></tr>
</tbody></table>
</center>
<br/><br/><center id='center30155'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30149" align="center" colspan="1"><font color="#ffffff"><strong id='bold30147'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30152" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-1.html#Acknowledgements">Acknowledgements</a></td></tr>
 <tr><td valign="top" align="left">1</td><td colspan="4" width="100%"><a href="bigloo-2.html#Table-of-contents">Table of contents</a></td></tr>
 <tr><td valign="top" align="left">2</td><td colspan="4" width="100%"><a href="bigloo-3.html#Overview-of-Bigloo">Overview of Bigloo</a></td></tr>
 <tr><td valign="top" align="left">3</td><td colspan="4" width="100%"><a href="bigloo-4.html#Modules">Modules</a></td></tr>
 <tr><td valign="top" align="left">4</td><td colspan="4" width="100%"><a href="bigloo-5.html#Core-Language">Core Language</a></td></tr>
 <tr><td valign="top" align="left">5</td><td colspan="4" width="100%"><a href="bigloo-6.html#DSSSL-support">DSSSL support</a></td></tr>
 <tr><td valign="top" align="left">6</td><td colspan="4" width="100%"><a href="bigloo-7.html#Standard-Library">Standard Library</a></td></tr>
 <tr><td valign="top" align="left">7</td><td colspan="4" width="100%"><a href="bigloo-8.html#Pattern-Matching">Pattern Matching</a></td></tr>
 <tr><td valign="top" align="left">8</td><td colspan="4" width="100%"><a href="bigloo-9.html#Fast-search">Fast search</a></td></tr>
 <tr><td valign="top" align="left">9</td><td colspan="4" width="100%"><a href="bigloo-10.html#Structures-and-Records">Structures and Records</a></td></tr>
 <tr><td valign="top" align="left">10</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-System">Object System</a></td></tr>
 <tr><td valign="top" align="left">11</td><td colspan="4" width="100%"><a href="bigloo-12.html#Regular-parsing">Regular parsing</a></td></tr>
 <tr><td valign="top" align="left">12</td><td colspan="4" width="100%"><a href="bigloo-13.html#Lalr(1)-parsing">Lalr(1) parsing</a></td></tr>
 <tr><td valign="top" align="left">13</td><td colspan="4" width="100%"><a href="bigloo-14.html#Posix-Regular-Expressions">Posix Regular Expressions</a></td></tr>
 <tr><td valign="top" align="left">14</td><td colspan="4" width="100%"><a href="bigloo-15.html#Command-Line-Parsing">Command Line Parsing</a></td></tr>
 <tr><td valign="top" align="left">15</td><td colspan="4" width="100%"><a href="bigloo-16.html#Cryptography">Cryptography</a></td></tr>
 <tr><td valign="top" align="left">16</td><td colspan="4" width="100%"><a href="bigloo-17.html#Errors-Assertions-and-Traces">Errors, Assertions, and Traces</a></td></tr>
 <tr><td valign="top" align="left">17</td><td colspan="4" width="100%"><a href="bigloo-18.html#Threads">Threads</a></td></tr>
 <tr><td valign="top" align="left">18</td><td colspan="4" width="100%"><a href="bigloo-19.html#Database-library">Database library</a></td></tr>
 <tr><td valign="top" align="left">19</td><td colspan="4" width="100%"><a href="bigloo-20.html#Multimedia-library">Multimedia library</a></td></tr>
 <tr><td valign="top" align="left">20</td><td colspan="4" width="100%"><a href="bigloo-21.html#Mail-library">Mail library</a></td></tr>
 <tr><td valign="top" align="left">21</td><td colspan="4" width="100%"><a href="bigloo-22.html#Eval-and-code-interpretation">Eval and code interpretation</a></td></tr>
 <tr><td valign="top" align="left">22</td><td colspan="4" width="100%"><a href="bigloo-23.html#Macro-expansion">Macro expansion</a></td></tr>
 <tr><td valign="top" align="left">23</td><td colspan="4" width="100%"><a href="bigloo-24.html#Parameters">Parameters</a></td></tr>
 <tr><td valign="top" align="left">24</td><td colspan="4" width="100%"><a href="bigloo-25.html#Explicit-typing">Explicit typing</a></td></tr>
 <tr><td valign="top" align="left">25</td><td colspan="4" width="100%"><a href="bigloo-26.html#The-C-interface">The C interface</a></td></tr>
 <tr><td valign="top" align="left">26</td><td colspan="4" width="100%"><a href="bigloo-27.html#The-Java-interface">The Java interface</a></td></tr>
 <tr><td valign="top" align="left">27</td><td colspan="4" width="100%"><a href="bigloo-28.html#Bigloo-Libraries">Bigloo Libraries</a></td></tr>
 <tr><td valign="top" align="left">28</td><td colspan="4" width="100%"><a href="bigloo-29.html#Extending-the-Runtime-System">Extending the Runtime System</a></td></tr>
 <tr><td valign="top" align="left">29</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFIs">SRFIs</a></td></tr>
 <tr><td valign="top" align="left">30</td><td colspan="4" width="100%"><a href="bigloo-31.html#Compiler-description">Compiler description</a></td></tr>
 <tr><td valign="top" align="left">31</td><td colspan="4" width="100%"><a href="bigloo-32.html#User-Extensions">User Extensions</a></td></tr>
 <tr><td valign="top" align="left">32</td><td colspan="4" width="100%"><a href="bigloo-33.html#Bigloo-Development-Environment">Bigloo Development Environment</a></td></tr>
 <tr><td valign="top" align="left">33</td><td colspan="4" width="100%"><a href="bigloo-34.html#Global-Index">Global Index</a></td></tr>
 <tr><td valign="top" align="left">34</td><td colspan="4" width="100%"><a href="bigloo-35.html#Library-Index">Library Index</a></td></tr>
 <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-36.html#Bibliography">Bibliography</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
</div></td>
<td align="left" valign="top" class="skribe-body"><div class="skribe-body">
<a name="Explicit-Typing" class="mark"></a><a name="g22843" class="mark"></a>
Bigloo supports <em id='emph22845'
>type annotation</em> or <em id='emph22846'
>type information</em>. As shown in
Section ref Module declaration, these annotations can be written both in
the module clauses and in module bodies although module body type
information is optional. It helps the compiler to produce better quality
code and to reject incorrectly typed programs. Type annotations can describe
both the result and formal parameter types for global functions and also
types for local variable. Due to our module language design (in particular
module initialization), Scheme global variables <em id='emph22847'
>cannot</em> support type
information.<br/><br/><em id='emph22849'
>Warning: </em> All type annotations are ignore by the interpreter.<br/><br/>Module body type annotations are introduced by the following
special forms.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22854" align="left" colspan="1"><strong id='bold22852'
>define</strong><em id='it22853'
> (f[::type] [a[::type]]...) body</em></td><td id="tc22855" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22860" align="left" colspan="1"><strong id='bold22858'
>define-inline</strong><em id='it22859'
> (f[::type] [a[::type]]...) body</em></td><td id="tc22861" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22866" align="left" colspan="1"><strong id='bold22864'
>let</strong><em id='it22865'
> ((var[::type] ...) ...) body</em></td><td id="tc22867" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22872" align="left" colspan="1"><strong id='bold22870'
>let</strong><em id='it22871'
> loop ((var[::type] ...) ...) body</em></td><td id="tc22873" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22878" align="left" colspan="1"><strong id='bold22876'
>let*</strong><em id='it22877'
> ((var[::type] ...) ...) body</em></td><td id="tc22879" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22884" align="left" colspan="1"><strong id='bold22882'
>letrec</strong><em id='it22883'
> ((var[::type] ...) ...) body</em></td><td id="tc22885" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc22890" align="left" colspan="1"><strong id='bold22888'
>labels</strong><em id='it22889'
> ((var[::type] (var[::type]...) b) ...) body</em></td><td id="tc22891" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

Type annotations are optional. That is, for any of these
constructions, if a type annotation is missing, Bigloo uses
the default generic type <code id='code22894'
>obj</code> instead.<br/><br/>Here is an example of type annotated program:<br/><br/><center id='center22916'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog22914'
>(<font color="#1919af"><strong id='bold30156'
>module</strong></font> <font color="#1919af"><strong id='bold30158'
>example</strong></font>
   (<font color="#1919af"><strong id='bold30160'
>export</strong></font> (<font color="#1919af"><strong id='bold30162'
>vector-fill!</strong></font><font color="#00cf00"><strong id='bold30164'
>::vector</strong></font> <font color="#00cf00"><strong id='bold30166'
>::vector</strong></font> <font color="#00cf00"><strong id='bold30168'
>::obj</strong></font>)))<br/><br/>(<font color="#6959cf"><strong id='bold30170'
>define</strong></font> (<font color="#6959cf"><strong id='bold30172'
>vector-fill!</strong></font> v filler)
  (<strong id='bold30174'
>let</strong> loop ((i<font color="#00cf00"><strong id='bold30175'
>::long</strong></font> (- (vector-length v) 1)))
     (<strong id='bold30177'
>if</strong> (&lt; i 0)
         v
         (<strong id='bold30178'
>begin</strong>
            (vector-set! v i filler)
            (loop (- i 1))))))<br/><br/>(<strong id='bold30179'
>let</strong> ((v<font color="#00cf00"><strong id='bold30180'
>::vector</strong></font> (make-vector 3 4)))
   (vector-fill! v <font color="red">&quot;dummy&quot;</font>))
</pre>
</td></tr>
</tbody></table></center>

The types that can be used in annotations are any of: <br/><br/><ul class="itemize" id='itemize22930'
><li>the basic Scheme types <code id='code22918'
>pair</code>, <code id='code22919'
>null</code>, <code id='code22920'
>bstring</code>,
<code id='code22921'
>bint</code> (presented in Section <a href="bigloo-26.html#Defining-an-extern-type" class="inbound">Defining an extern type</a>).
</li>
<li>the basic extern types <code id='code22923'
>long</code>, <code id='code22924'
>int</code>, <code id='code22925'
>char</code>, 
<code id='code22926'
>string</code> presented in Section <a href="bigloo-26.html#Defining-an-extern-type" class="inbound">Defining an extern type</a>.
</li>
<li>the compound extern types described in Section 
<a href="bigloo-26.html#Defining-an-extern-type" class="inbound">Defining an extern type</a>.
</li>
<li>the types introduced by class declarations (Section 
<a href="bigloo-11.html#Class-declaration" class="inbound">Class declaration</a>).
</li>
</ul><br/><br/>When a function that contains type annotation is exported, the type 
annotations must be written in the prototype of the function in
the export clause. In that case the type annotation need to be
written in the function definition:<br/><br/><center id='center22943'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog22941'
>(<font color="#1919af"><strong id='bold30183'
>module</strong></font> <font color="#1919af"><strong id='bold30185'
>foo</strong></font>
   (<font color="#1919af"><strong id='bold30187'
>export</strong></font> (<font color="#1919af"><strong id='bold30189'
>succ</strong></font><font color="#00cf00"><strong id='bold30191'
>::int</strong></font> <font color="#00cf00"><strong id='bold30193'
>::int</strong></font>)))<br/><br/>(<font color="#6959cf"><strong id='bold30195'
>define</strong></font> (<font color="#6959cf"><strong id='bold30197'
>succ</strong></font> x) (+ 1 x))
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>


</div></td>
</tr></table><div class="skribe-ending">
<hr> 
<p class="ending" id='paragraph30204'
><font size="-1">
This <span class="sc">Html</span> page has been produced by 
<a href="http://www.inria.fr/mimosa/fp/Skribe" class="http">Skribe</a>.
<br/>
Last update <em id='it30202'
>Tue Jun  2 11:43:27 2009</em>.</font></p></div>
</body>
</html>