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