demo.xml 5.95 KB
Newer Older
1
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2
3
4
5
<!DOCTYPE page [
  <!ENTITY leq     "&#x2264;"> <!-- LESS_THAN OR EQUAL TO -->
]>
<page name="demo">
6
7
<title>CDuce demo at PLANX 2005</title>

8
<box title="CDuce: introduction, project status" link="intro">
9
10
11

<p>
This page is the support for the CDuce demo at the PLANX 2005 workshop
12
(Longbeach).
13
14
</p>

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
<section title="Hightlights of CDuce">
<ul>
<li>XML-oriented.</li>
<li>Type centric.</li>
<li>Based on regular expression types and patterns.</li>
<li>Also general purpose features, including 
   <b>higher-order and overloaded functions</b>.</li>
<li>Reasonnably efficient implementation.</li>
</ul>
</section>

<section title="Papers">
<ul>
<li>White paper (PLANX 2002).</li>
<li>Language description (ICFP 2003).</li>
<li>Theoretical foundations (LICS 2002).</li>
<li>Compilation of pattern matching (PLANX 2004, TCS 2004).</li>
<li>Query language (PADL 2005).</li>
</ul>
</section>

<section title="Distribution">
<p>
Public release since June 2003. Now at version 0.2.1,
which includes a <b>typeful and lightweight OCaml/CDuce interface</b>.
A few users (static/dynamic websites, code generation
from GUI description, teaching, ...). Development continues.
</p>
</section>

<section title="This demo">
46
47
<p>
The demo illustrates the use of first-class functions
48
49
in XML transformations. Here, functions are stored within documents.
</p>
50
</section>
51
52
53
54

<boxes-toc/>

</box>
55

56
<box title="Types, pattern matching" link="typpm">
57
58
59
60
61
62
63
<demo><![CDATA[
type Bib = [ Book* ]
type Book = <book>[ Title Subtitle? Author+ ]
type Title = <title>[ PCDATA ]
type Subtitle = <subtitle>[ PCDATA ]
type Author = <author>[ PCDATA ]

64
65
66
67
68
let title(Book -> String) 
  <book>[ <title>x _* ] -> x

let authors(Book -> [Author+]) 
  <book>[ (x::Author|_)* ] -> x
69
]]></demo></box>
70

71
72
73
74
75
76
77
78
79
80
<box title="Sample values" link="samp"><demo prefix="last"><![CDATA[
let b1 : Book = <book>[ 
            <title>[ 'Object-Oriented Programming' ]
            <subtitle>[ 'A Unified Foundation' ]
            <author>[ 'Castagna' ] ]
let b2 : Book = <book>[
            <title>[ 'Persistent Object Systems' ]
            <author>[ 'Atkinson' ]
            <author>[ 'Benzaken' ]
            <author>[ 'Maier' ] ]
81
let bib : Bib = [ b1 b2 ]
82
83
84
]]></demo></box>

<box title="Printing functions" link="printfun"><demo prefix="last"><![CDATA[
85
86
87
88
89
type FBook = Book -> String
type ABook = <book print=FBook>[ Title Subtitle? Author+ ]
type ABib = [ ABook* ]
  (* Remark: ABook <= Book,  ABib <= Bib *)

90
91
92
93
94
let set(<book>c : Book)(f : FBook) : ABook = 
  <book print=f>c

let prepare(b : Bib) : ABib = 
  map b with x -> set x title
95

96
97
98
99
100
101
let abib = prepare bib
]]></demo></box>

<box title="Display" link="display"><demo prefix="last"><![CDATA[
type Ul = <ul>[ Li+ ]
type Li = <li>[ PCDATA ]
102

103
104
105
106
107
108
let display (ABib -> Ul; ABook -> Li)
 | <book print=f>_ & x -> <li>(f x)
 | [] -> raise "Empty bibliography"
 | p -> <ul>(map p with z -> display z)

let d = display abib
109
]]></demo></box>
110

111
<box title="Changing the style" link="style"><demo prefix="last"><![CDATA[
112
113
114
let change(p : Book -> Bool)
          (f : FBook)
          (b : ABib) : ABib =
115
 map b with x -> if (p x) then set x f else x
116

117
type HasSub = <_>[ _* Subtitle _* ]
118

119
120
let subtitle(Book & HasSub -> String) 
  <book>[ _* <subtitle>x _* ] -> x
121

122
123
124
125
126
let change_sub = 
change 
 (fun (Book -> Bool) HasSub -> `true | _ -> `false)
 (fun (b : Book) : String = 
   title b @ ": " @ subtitle (b :? HasSub))
127
128
129

let subtitle_first(Bib -> Bib; ABib -> ABib)
 [ (x::HasSub|y::_)* ] -> x @ y
130
]]></demo></box>
131

132
133
134
135
136
137
138
<box title="Compilation of pattern-matching" link="pm"><demo prefix="last"><![CDATA[
debug compile 
(*typ*) [ Title Subtitle? Author+ ] 
(*pat*) [ (x::Author|_)* ]
]]></demo></box>


139
140
141
142
<box title="Thank you !" link="concl">
<p>CDuce website: <a href="http://www.cduce.org/">http://www.cduce.org</a>.</p>
</box>

143
<!--
144
145
146
147
148
149
150
151
152
153
154
155
156
<box title="XML elements" link="xml">
<p>XML elements.</p>
<demo><include-verbatim file="examples/xml.cd"/></demo>
</box>

<box link="functions"  title="Functions">
<p>Several syntaxes to define functions.</p>
<demo><include-verbatim file="examples/functions.cd"/></demo>
</box>

<box link="mutrec" title="Mutual recursion">
<p>Mutual toplevel definition for types and functions.</p>
<demo><include-verbatim file="examples/mutrec.cd"/></demo>
157
158
</box>

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<box link="sequence" title="Sequence literals">
<p>How to write sequences.</p>
<demo><include-verbatim file="examples/sequence.cd"/></demo>
</box>

<box link="seqtypes" title="Sequence types">
<p>Types for sequences.</p>
<demo><include-verbatim file="examples/seqtypes.cd"/></demo>
</box>

<box link="integers" title="The factorial function">
<p>What about computing 10000! ?</p>
<demo><include-verbatim file="examples/integers.cd"/></demo>
</box>

<box link="sumtype" title="Sum types">
<p>How to simulate ML sum types.</p>
<demo><include-verbatim file="examples/sumtype.cd"/></demo>
</box>
178

179
180
181
<box link="ovfun" title="Overloaded functions">
<p>This examples demonstrates the use of overloaded functions.</p>
<demo><include-verbatim file="examples/ovfun.cd"/></demo>
182
183
</box>

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<box link="note" title="Footnotes">
<p>This example shows how to bind an XML element with surrounding text.</p>
<demo><include-verbatim file="examples/note.cd"/></demo>
</box>

<box link="biblio" title="Bibliography">
<p>The good old XML bibliography example.</p>
<demo><include-verbatim file="examples/biblio.cd"/></demo>
</box>

<box link="projection" title="Projection">
<p>Syntactic sugar for projection.</p>
<demo><include-verbatim file="examples/projection.cd"/></demo>
</box>

<box link="xtransform" title="Tree transformations">
<p>How to perform XSLT-like transformations.</p>
<demo><include-verbatim file="examples/xtransform.cd"/></demo>
</box>

<box link="reference" title="References">
<p>Mutable values.</p>
<demo><include-verbatim file="examples/reference.cd"/></demo>
</box>

<box title="Compilation of pattern matching" link="pm_compil">
<p>This example demonstrates the efficient compilation of pattern
matching.</p>
<demo><include-verbatim file="examples/pm_compil.cd"/></demo>
213
</box>
214
-->
215
216

</page>