| 1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
|
| 2 |
<page name="examples">
|
| 3 |
|
| 4 |
<title>Code examples</title>
|
| 5 |
|
| 6 |
<left>
|
| 7 |
<p>This page presents some simple CDuce programs.</p>
|
| 8 |
<boxes-toc/>
|
| 9 |
<p>See also:</p>
|
| 10 |
<local-links href="index,proto,memento"/>
|
| 11 |
</left>
|
| 12 |
|
| 13 |
<box title="Our canonical example" link="sort">
|
| 14 |
<p>
|
| 15 |
The example below is the one we use to demonstrate
|
| 16 |
how overloaded functions can avoid duplicating code.
|
| 17 |
Without overloaded functions, we would need to define
|
| 18 |
two mutually recursive functions in order to type-check
|
| 19 |
the transformation. Here, two constraints
|
| 20 |
in the (highlighted) function interface
|
| 21 |
can express precisely the behaviour of the function.
|
| 22 |
</p>
|
| 23 |
<sample>
|
| 24 |
<include-verbatim file="overloading.cd"/>
|
| 25 |
</sample>
|
| 26 |
</box>
|
| 27 |
|
| 28 |
<box title="The script that generates this site" link="site">
|
| 29 |
<p>
|
| 30 |
The script below is one of the longest CDuce application ever written
|
| 31 |
;-) It is used to produce all the pages of this web site (except
|
| 32 |
the <local href="proto">web prototype</local> which is
|
| 33 |
a CGI script written in OCaml). CDuce type system ensures
|
| 34 |
that produced pages are valid w.r.t XHTML 1.0 Strict.
|
| 35 |
</p>
|
| 36 |
<p>
|
| 37 |
This program features both XML and text-content manipulation.
|
| 38 |
It also demonstrates the use of non-XML internal data structures.
|
| 39 |
Here, a tree represents internally the site
|
| 40 |
structure, and a list represents the path from the
|
| 41 |
root to the current page (in order to display the "You're here" line).
|
| 42 |
</p>
|
| 43 |
<sample highlight="false">
|
| 44 |
<include-verbatim file="site.cd"/>
|
| 45 |
</sample>
|
| 46 |
</box>
|
| 47 |
|
| 48 |
</page>
|
| 49 |
|