.
[hacks/simpleWebSlides.git] / pres-esop15 / 01.xhtml
1 <?xml version="1.0" encoding="utf-8" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
4 [
5           <!ENTITY in  "<small style='font-size:small'>∈</small>">
6           <!ENTITY notin  "<small style='font-size:small'>∉</small>">
7           <!ENTITY emptyset  "⦰">
8           <!ENTITY cup       "∪">
9           <!ENTITY cap       "∩">
10           <!ENTITY mapsto  "↦">
11           <!ENTITY rarrow   "⟶">
12           <!ENTITY rsarrow   "→">
13           <!ENTITY cduce   "&#x2102;Duce">
14           <!ENTITY land    "∧" >
15           <!ENTITY lor      "∨" >
16           <!ENTITY setminus "∖" >
17           <!ENTITY bottom   "<tt>Empty</tt>" > <!-- 𝟘 -->
18           <!ENTITY top      "<tt>Any</tt>" > <!-- 𝟙 -->
19           <!ENTITY subseteq "⊆" >
20           <!ENTITY leq      "≤" >
21           <!ENTITY Lrarrow  "⟺">
22           <!ENTITY lbag  "⟅">
23           <!ENTITY rbag  "⟆">
24           <!ENTITY lbrack "<span style='font-size:xx-large;'>⟦</span>" >
25           <!ENTITY rbrack "<span style='font-size:xx-large;'>⟧</span>" >
26           <!ENTITY bcirc  "⏺" >
27           <!ENTITY left  "<tt style='color:#d33'>L</tt>" >
28           <!ENTITY right  "<tt style='color:#33d'>R</tt>">
29           <!ENTITY ztop      "⊤" >
30           <!ENTITY rleadsto  "⟿"> <!-- -->
31           <!ENTITY rwave   "↝">
32           <!ENTITY mathV     "𝓥">
33           <!ENTITY mathT     "𝓣">
34           <!ENTITY vdash     "⊢">
35 ]
36           >
37 <html xmlns="http://www.w3.org/1999/xhtml" >
38   <head>
39     <title>A Core Calculus for XQuery 3.0</title>
40
41     <meta http-equiv="Content-Type"
42           content="text/html; charset=utf-8" />
43     <meta name="copyright"
44           content="Copyright &#169; 2013 Kim Nguyễn" />
45
46     <!-- Load jQuery -->
47     <script src="../jquery-2.0.3.min.js" type="text/javascript" ></script>
48     <script src="../libs/raphael-min.js" type="text/javascript" ></script>
49     <!-- Load the library -->
50     <script src="../simpleWebSlides.js" type="text/javascript" ></script>
51
52     <link rel="stylesheet" href="../simpleWebSlides.css" type="text/css"  media="all" />
53     <!-- Load a custom Theme, the class-element marks this style-sheet
54          a "theme" that can be swtiched dynamicaly -->
55     <link class="sws-theme" rel="stylesheet"  title="U-Psud style"  href="../themes/uPsud.css" type="text/css" />
56
57     <!-- Customize some templates and initialize -->
58
59     <script type="text/javascript">
60       SWS.Config['sws-slide-change'] = SWS.Effects.slideChangeFadeOutIn;
61       SWS.Config['sws-object-deactivate'] =  SWS.Effects.objectDeactivateFadeOut;
62       SWS.Config['sws-object-activate'] = SWS.Effects.objectActivateFadeIn;
63
64       //Ensures that we load SWS at the very end, after MathJax has
65       //been initialized
66
67       $(window).load(SWS.Presentation.init);
68
69       var col_change = function (sel, col) {
70       return function (canvas) {
71         canvas.find(".xpath *").css("color","");
72         var objs = canvas.find(sel);
73         objs.css("color", col);
74       };
75       };
76       var reg = SWS.Presentation.registerCallback;
77     </script>
78     <style>
79       <![CDATA[
80
81        @font-face {
82          src: url("OpenSans-Regular.ttf") format("truetype");
83          font-family: "Open Sans";
84          font-weight: normal;
85        }
86
87       @font-face {
88          src: url("OpenSans-Bold.ttf") format("truetype");
89          font-family: "Open Sans";
90          font-weight: bold;
91        }
92
93       @font-face {
94          src: url("OpenSans-Italic.ttf") format("truetype");
95          font-family: "Open Sans";
96          font-style: italic;
97        }
98
99       @font-face {
100          src: url("OpenSans-BoldItalic.ttf") format("truetype");
101          font-family: "Open Sans";
102          font-weight: bold;
103          font-style: italic;
104        }
105
106          ]]>
107
108       body {
109       font-family: 'Open Sans',sans-serif;
110       font-size: 3.75vh;
111       background-color: white;
112       color:  #393938;
113       }
114
115       .sws-canvas {
116             color: #393938;
117       }
118       code, tt {
119                   color: #292928;
120       }
121       pre, dfn, .infer { font-family : serif;
122       font-style:normal;
123       color: #292928;
124       }
125
126       .stack {
127       text-align:center;
128       vertical-align:text-bottom;
129       display:inline-block;
130       }
131       .over {
132       display:block;
133       font-size:small;
134       margin: 0pt;
135       padding: 0pt;
136       }
137
138       .infer {
139       text-align:center;
140       vertical-align:text-bottom;
141       display:inline-block;
142       margin-bottom:1em;
143       margin-top:0em;
144       }
145       .infer > span {
146                display:block;
147                margin: 0pt 0pt 0pt 0pt;
148                padding: 0pt 0pt 0pt 0pt;
149                border-width: 0pt;
150       }
151       .infer > span:last-child {
152                margin: 0pt 0pt 0pt 0pt;
153                padding: 0pt 0pt 0pt 0pt;
154                border-width: 1pt 0pt 0pt 0pt;
155                border-style: solid;
156                border-color:  #292928;
157       }
158       .infer + span {
159                vertical-align:text-top;
160                position:relative;
161                top:-1.75em;
162                display:inline;
163                font-size:80%;
164                color: #00486c;
165                margin: 0pt 0pt 0pt 0pt;
166                padding: 0pt 0pt 0pt 0pt;
167       }
168       span.fill { display:inline-block;
169                   width:100%;
170                   height: 0pt;
171       }
172
173     </style>
174   </head>
175   <body>
176     <div class="sws-slide sws-cover sws-option-nofooter">
177       <h1 style="font-size:200%;position:relative;top:-1em;">A Core Calculus for XQuery 3.0</h1>
178       <h3>Combining Navigational and Pattern-Matching Approaches</h3>
179       <div style="text-align:center;">
180         <table style="display:inline-block">
181           <tr>
182             <td>Giuseppe Castagna<sup>1</sup></td>
183             <td>Hyeonseung Im<sup>2</sup></td>
184           </tr>
185           <tr>
186             <td><u>Kim Nguyễn</u><sup>3</sup></td>
187             <td>Véronique Benzaken<sup>3</sup></td>
188           </tr>
189         </table>
190       </div>
191       <p style="font-size:80%;position:absolute;bottom:2.5em;left:4em;">
192         1 CNRS, PPS, Université Paris-Diderot, Paris, France <br/>
193         2 Kangwon National University, Chuncheon, Rep. of Korea<br/>
194         3 LRI, Université Paris-Sud, Orsay, France
195       </p>
196     </div>
197     <div class="sws-slide">
198       <h1>The XQuery 3.0 W3C Standard</h1>
199 <code style="background:white;font-size:90%;">
200
201    declare function <u>get_links</u>(<u>$page</u>, <u>$print</u>) {
202        <span class="for">for</span> <u>$i</u> <span class="for">in</span> <u>$page</u><span class="xpath">/descendant::a[not(ancestor::b)]</span>
203        <span class="for">return</span> <u>print</u>(<u>$i</u>)
204    }
205
206    declare function <u>pretty</u>(<u>$link</u>) {
207        <span class="ts">typeswitch</span>(<u>$link</u>)
208            <span class="ts">case</span> <u>$l</u> <span class="ts">as element(a)</span>
209               return <span class="sw">switch</span> (<u>$l</u><span class="xpath">/@class</span>)
210                  <span class="sw">case</span> "style1"
211                      return &lt;a href={<u>$l</u><span class="xpath">/@href</span>}&gt;&lt;b&gt;{<u>$l</u><span class="xpath">/text()</span>}&lt;/b&gt;&lt;/a&gt;
212                  default return <u>$l</u>
213
214            <span class="ts">default return</span> <u>$link</u>
215    }
216    
217    let $bold_links := get_links(document("file.html"), $pretty)
218 </code>
219     <script type="text/javascript">
220       reg ("0", col_change(".xpath, .for, .ts, .sw",""));
221       reg ("1", col_change(".xpath", "#f80"));
222       reg ("2", col_change(".for",""));
223       reg ("2", col_change(".for", "#290"));
224       reg ("3", col_change(".ts", ""));
225       reg ("3", col_change(".ts", "#80f"));
226       reg ("4", col_change(".sw", ""));
227       reg ("4", col_change(".sw", "#0f2"));
228     </script>
229     </div>
230     <div class="sws-slide">
231       <h1>XQuery 3.0</h1>
232       <ul>
233         <li>Pros<br/>
234           + standardized <br/>
235           + nice declarative syntax for paths
236         </li>
237         <li>Cons<br/>
238           - weird distinction between types/value case<br/>
239           - <s>no type-checking for functions</s>
240         </li>
241       </ul>
242       <p>It's a pity since XML <em>documents</em> are very precisely
243       typed (DTD, XMLSchemas)</p>
244       <p>Document type information is validated at runtime rather than
245       checked statically</p>
246     </div>
247     <div class="sws-slide">
248       <h1>&cduce;</h1>
249       <p>A polymorphic functional language equipped with
250       semantic subtyping</p>
251
252 <code style="font-size:90%">   <i>(* Here _ is an alias for the top type Any *)</i>
253
254   let <u>pretty</u> (&lt;a&gt;Any <span class="typ">&rarrow;</span> &lt;a&gt;Any  <span class="typ">&amp;</span>  Any<span class="typ">\</span>&lt;a&gt;Any <span class="typ">&rarrow;</span> Any<span class="typ">\</span>&lt;a>Any)
255
256     | <span class="pat">&lt;a class="style1" href=<u>h</u> ..&gt; <u>l</u></span> &rarrow; &lt;a href=<u>h</u>&gt;[ &lt;b&gt;<u>l</u> ]
257     | <span class="pat">x</span> &rarrow; x
258
259
260   let <u>get_links</u> (page: &lt;(Any)&gt;Any) (print: &lt;a&gt;Any <span class="typ">&rarrow;</span> &lt;a&gt;Any) : <span class="typ">[ &lt;a&gt;Any * ]</span> =
261
262       match page with
263       <span class="pat">&lt;a&gt;_ &amp; x</span> &rarrow; [ (print x) ]
264     | <span class="pat">&lt; (_\‘b) &gt; l</span> &rarrow;
265                  (<span class="lc">transform l with</span> <span class="pat">(i &amp; &lt;_&gt;_)</span> &rarrow; get_links i print)
266     | <span class="pat">_</span> &rarrow; [ ]
267 </code>
268         <script type="text/javascript">
269           reg ("0", col_change(".pat,.typ,.lc",""));
270           reg ("1", col_change(".pat", "#f80"));
271           reg ("2", col_change(".typ", "#290"));
272           reg ("3", col_change(".lc", "#80f"));
273     </script>
274
275     </div>
276     <div class="sws-slide">
277       <h1>&cduce;</h1>
278       <ul>
279         <li>Pros<br/>
280           + Statically typed <br/>
281           + compact (and efficient) type and value pattern-matching
282         </li>
283         <li>Cons<br/>
284           - <s>complex navigation encoded through recursion</s><br/>
285           - no type inference for functions
286         </li>
287       </ul>
288       <p>Writing functions to traverse documents is painfull</p>
289     </div>
290     <div class="sws-slide">
291       <h1>This work</h1>
292       <ol style="margin-left:1em; margin-right:0.25em;list-style-position:inside;">
293         <li id="tobox" style="padding:1em 0em 1em 0em;"><span class="lh">Add support for path navigation to
294             &cduce;</span>
295           <ul style="margin-top:2em;">
296             <li>Enrich the type algebra with <em>zippers</em> (à la Huet)</li>
297             <li>Extend pattern-matching construct to <em>zipped values  and types</em></li>
298             <li>Encode path expressions as recursive patterns</li>
299           </ul>
300         </li>
301         <li class="ll" style="padding:1em 0em 1em 0em;">Perform a type-directed translation from XQuery to
302           &cduce;</li>
303       </ol>
304       <script type="text/javascript">
305         reg (1, col_change(".lh", "#f83"));
306         reg (1, col_change(".ll", "#bbb"));
307       </script>
308     </div>
309     <div class="sws-slide">
310       <h1>&cduce;'s type algebra</h1>
311 <p>A set &mathT; of types</p>
312 <pre style="text-align:center;">    t ::=  b  |  c  |  <u>t × t</u>  |  <u>t &rarrow; t</u>  |  <mark>t &lor; t</mark>  |  <mark>t  &land; t</mark>  |  <mark>t &setminus; t</mark>  |  <mark>&top;</mark>  |  <mark>&bottom;</mark>  |  &alpha;
313 </pre>
314 <p><dfn>b</dfn> : ranges over basic types (<tt>Int</tt>, <tt>String</tt>, …)<br/>
315    <dfn>c</dfn> : ranges over singleton types
316    (<tt>`A</tt>, <tt>42</tt>, …)<br/>
317    <u>Type constructors</u> <br/>
318    <mark>Boolean connectives</mark> <br/>
319    <dfn>&alpha;</dfn> : type variables<br/>
320    types are interpreted co-inductively: recursive types and regular
321    expression types<br/>
322 </p>
323 <div style="vertical-align:top;">
324 <pre style="width:50%;display:inline-block;">      t<sub>1</sub> ≡ (<tt>Int</tt> × t<sub>1</sub>)    &lor;    t<sub>2</sub>
325       t<sub>2</sub> ≡ (<tt>Bool</tt> × t<sub>2</sub>)  &lor; (<tt>Bool</tt> × <tt>`nil</tt>)
326 </pre>
327 <pre style="width:30%;display:inline-block;"> <span class="sws-pause">t<sub>1</sub> ≡ <tt>[ Int* Bool+ ]</tt></span></pre>
328 </div>
329     </div>
330     <div class="sws-slide">
331       <h1>Semantic subtyping</h1>
332 <pre style="text-align:center;">
333 t &leq; s   &Lrarrow;   &lbrack;t&rbrack; &subseteq;  &lbrack;s&rbrack;
334 </pre>
335 <p><dfn>&lbrack; &rbrack;</dfn> interpretation of types as sets of
336   values<br/>
337   Allows to reason <i>modulo</i> semantic equivalence of type connectives :
338 </p>
339 <pre >
340       <tt>[ Int* (Int | Bool*)? ]</tt> &land; <tt>[ Int+ (Bool+ | Int)* ]</tt> ≡ <tt>[Int+ Bool*]</tt>
341 </pre>
342 </div>
343 <div class="sws-slide">
344 <h1>&cduce; data-model</h1>
345 <p>The usual sets &mathV; of values:</p>
346 <pre style="text-align:center">       v ::= <tt>1</tt>  |  …  |  <tt>`Foo</tt>  |   (v, v)  |  &lambda;x.e
347 </pre>
348 <p>Sequences are nested pairs (<i>à la</i> Lisp):</p>
349 <pre style="text-align:center;"><tt>[</tt> v<sub>1</sub>  … v<sub>n</sub> <tt>]</tt> ≡ (v<sub>1</sub>, (…, (v<sub>n</sub>, <tt>`nil</tt>)))
350 </pre>
351 <p>XML documents are tagged sequences: <pre style="text-align:center;"><tt>&lt;foo&gt;[</tt> v<sub>1</sub>  … v<sub>n</sub> <tt>]</tt> ≡ (<tt>`foo</tt>, <tt>[</tt> v<sub>1</sub>  … v<sub>n</sub> <tt>]</tt>)</pre>
352 </p>
353 <p>(Sometimes we write <tt>[ ]</tt> for the variant <tt>`nil</tt>)</p>
354 <p>Everything is built on top of products and variants</p>
355 </div>
356 <div class="sws-slide">
357       <h1>&cduce; patterns</h1>
358 <p><i>(a.k.a. the left-hand side of an arrow in a match … with)</i></p>
359 <pre style="text-align:center;">    p ::=  t  | x | <u>(p, p)</u> |  <mark>p | p</mark>  |  <mark>p &amp; p</mark>    </pre>
360 <p><dfn>t</dfn> ranges over types<br/>
361   <dfn>x</dfn> ranges over capture variables<br/>
362   <u>Pair patterns</u><br/>
363   <mark> Alternation |, Intersection &amp;</mark><br/>
364   patterns are also co-inductively interpreted (recursive patterns)
365 </p>
366 <p><dfn><u>v / p</u></dfn> : matching a value against a pattern yields a
367   substitution from variables to values<br/>
368    <dfn><u>&lbag; p &rbag;</u></dfn> : the set of values accepted by a
369    pattern is <u>a type</u><br/>
370    <dfn><u> t / p</u></dfn> : matching a type against a pattern yields a
371    substitution from variables to types<br/>
372 </p>
373 </div>
374 <div class="sws-slide">
375       <h1>&cduce; patterns (example)</h1>
376 <p>Assume <tt><u>l</u></tt> has type <tt>[ Int+ Bool* ]</tt>,  consider:</p>
377 <code>
378        match <u>l</u> with
379        [ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ] &rarrow;  (<u>x</u>, <u>y</u>)
380     |  [ _* (<u>x</u> &amp; Int) ]                  &rarrow;  (<u>x</u>, `false)
381     |  [ ]                               &rarrow;  (0, `false)
382 </code>
383 <ol>
384 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ]</tt>&rbag;    <span style="display:inline-block;width:5em;text-align:center"> ≡</span>     <tt>[ &top;* Int Bool+ ]</tt></dfn><br/>
385  <span style="text-align:right;display:inline-block;width:94%;">{ x &mapsto; <tt>Int</tt>, y &mapsto; <tt>Bool</tt> }</span>
386 </li>
387 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) ]</tt>&rbag; <span style="display:inline-block;width:5em;text-align:center"> ≡</span> <tt>[ &top;* Int ]</tt></dfn><br/>
388   <span style="text-align:right;display:inline-block;width:58%;"> { x &mapsto; <tt>Int</tt> }</span>
389 </li>
390 <li>Since <dfn><tt>[Int+ Bool* ]</tt> &setminus; ( <tt>[ &top;* Int Bool+ ]</tt> &lor;  <tt>[ &top;* Int]</tt>) ≡ &bottom;  </dfn><br/>
391     the third case is unreachable.
392 </li>
393
394
395 </ol>
396
397 </div>
398
399 <div class="sws-slide">
400 <h1>Zippers (1/2)</h1>
401 <ul>
402   <li>Introduced in 1997 by Gérard Huet</li>
403   <li>Stack of visited nodes</li>
404   <li>Push the current node on the stack when traversing a pair</li>
405   <li>Take the top of the stack to go backward</li>
406   <li>Tag the elements of the stack to remember which component of a
407   pair we have visited</li>
408 </ul>
409 <pre style="text-align:center;"> v ::=  …  |  v<sub>&delta;</sub>
410  &delta; ::=  &bcirc;  | &left;v · &delta; | &right;v · &delta;
411 </pre>
412
413 </div>
414 <div class="sws-slide">
415 <h1>Zippers (2/2)</h1>
416 <p><tt><u>fst</u></tt> (resp. <tt><u>snd</u></tt>) takes the first (resp. second)
417   projection of a pair and update its zipper accordingly:</p>
418 <pre>    v<sub>1</sub> ≡ (1, (2, (3, (4, `nil))))<sub>&bcirc;</sub>
419     v<sub>11</sub> ≡ <tt>fst</tt> v<sub>1</sub> ≡ 1<sub>&left;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
420     v<sub>2</sub> ≡ <tt>snd</tt> v<sub>1</sub> ≡ (2, (3, (4, `nil)))<sub>&right;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
421     v<sub>3</sub> ≡ <tt>snd</tt> v<sub>2</sub> ≡ (3, (4, `nil))<sub>&right;v<sub>2</sub> · &right;v<sub>1</sub> · &bcirc; </sub>
422 </pre>
423 <p><tt><u>up</u></tt> returns the head of the zipper: </p>
424 <pre>    <tt>up</tt> v<sub>3</sub> ≡ v<sub>2</sub> ≡ (2, (3, (4, `nil)))<sub>&right;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
425 </pre>
426 </div>
427 <div class="sws-slide">
428   <h1>Zipper types</h1>
429 <p>We extend the type-algebra with zipper types:</p>
430 <pre style="text-align:center;"> t ::=  …  |  t<sub>&tau;</sub>
431  &tau; ::=  &bcirc;  |  &left;t · &tau;  | &right;t · &tau;  |  &tau; &lor; &tau;  |  &tau; &setminus; &tau;  |  &ztop;
432 </pre>
433 <p><dfn>&bcirc;</dfn>: singleton type denoting the empty zipper (root element)<br/>
434    <dfn>&ztop;</dfn>: the top zipper type<br/>
435    Zipper types are interpreted co-inductively<br/><br/>
436    <dfn><tt>Int</tt><sub>(&left;&top;)* &bcirc;</sub></dfn> <span style="float:right;">type of
437    integers that are the leftmost descendant of a tree</span><br/><br/>
438    <dfn><tt><![CDATA[<html>[ <head>[…] <body>[…] ]]]></tt><sub>&bcirc;</sub></dfn> <span style="float:right;">type of
439    HTML documents</span><br/><br/>
440    <dfn><tt><![CDATA[<a href=String>[ … ]]]></tt><sub> &ztop;</sub></dfn> <span style="float:right;">types of links  nested in any context</span>
441 </p>
442 </div>
443 <div class="sws-slide">
444 <h1>Tree navigation</h1>
445 <p>Since patterns contain types, we can check complex
446   conditions:</p>
447 <pre style="width:62%;display:inline-block;border-width:0pt 1pt 0pt
448   0pt; border-style:dashed;border-color: black;vertical-align:middle">  <span style="font-family:'Open Sans';">Has a descendant <tt>&lt;a&gt;_</tt>:</span>
449     p ≡ <tt id="test">&lt;a&gt;_</tt>   &lor;   <tt>&lt;_&gt;[ _* <dfn>p</dfn> _* ]</tt>
450  
451   <span style="font-family:'Open Sans';">Deos not have an ancestor <tt>&lt;b&gt;_</tt>:</span>
452     &tau; ≡ &bcirc;   &lor;   &right;(&top;&setminus; <tt>&lt;b&gt;_</tt>) · &tau;   &lor;   &left;(&top;&setminus; <tt>&lt;b&gt;_</tt>) · &tau; </pre>
453 <code style="width:20%;display:inline-block;vertical-align:middle">
454     match <u>v</u> with
455        <dfn>p<sub>&tau;</sub></dfn> &amp; <u>x</u> &rarrow; …
456    | _        &rarrow; …</code>
457 <p style="background:white">We want more, namely return <i>all</i> descendants (ancestors,
458   children,  siblings, …) of a node matching a particular condition
459 <br/><br/>
460 Remark: (recursive) patterns <u>already perform a recursive traversal
461   of the value</u>
462 <br/>
463 <em>Idea</em>: Piggy back on the traversal and <em>accumulate</em>
464 nodes in special variables
465 </p>
466 </div>
467 <div class="sws-slide">
468   <h1>Operators and Accumulators</h1>
469 <p>An <u>operator</u> is a 4-tupple <dfn>(o, n<sub>o</sub>,
470     &rleadsto;<sub>o</sub>, &rarrow;<sub>o</sub>)</dfn>, where:</p>
471 <p><dfn><u>o</u></dfn>: is the accumulator name<br/>
472 <dfn><u>n<sub>o</sub></u></dfn>: is the arity of <u>o</u><br/>
473 <dfn><u>&rleadsto;<sub>o</sub></u></dfn>:
474 &mathV;<sup>n<sub>o</sub></sup> &rsarrow; &mathV;, the reduction relation <br/>
475 <dfn><u>&rarrow;<sub>o</sub></u></dfn>:
476 &mathT;<sup>n<sub>o</sub></sup> &rsarrow; &mathT;, the typing relation <br/>
477 </p>
478 <p>An <u>accumulator</u> is a variable (ranged over
479   by <u>ẋ</u>, <u>ẏ</u>, …) with:<br/><br/>
480   <dfn><u>Op(ẋ)</u></dfn>: an operator<br/>
481   <dfn><u>Init(ẋ)</u> &in; &mathV;</dfn> : an initial value<br/>
482 </p>
483 </div>
484 <div class="sws-slide">
485   <h1>Some operators</h1>
486   <pre>
487     v, v' &rleadsto;<sup>cons,</sup> (v, v') <br/>
488     v, <tt>`nil</tt> &rleadsto;<sup>snoc</sup> (v, <tt>`nil</tt>)<br/>
489     v, (v',v'') &rleadsto;<sup>snoc</sup> (v', snoc(v,v''))<br/>
490   </pre>
491 <p>Now we can use accumulators equipped with cons/snoc in
492   patterns. Instead of matching a single node against a variable, it
493   <u>accumulates</u> that node in sequence (in reverse or in-order).</p>
494 </div>
495 <div class="sws-slide">
496 <h1>Pattern matching semantics (simplified)</h1>
497 <pre style="text-align:center;">
498   &sigma; &vdash; v / p &rleadsto; &gamma;, &sigma;'
499 </pre>
500 <p style="font-size:90%"><dfn><u>&sigma;</u>, <u>&sigma;'</u></dfn>: mapping from accumulators to
501   values<br/>
502   <dfn><u>v</u></dfn>: input value<br/>
503   <dfn><u>p</u></dfn>: pattern<br/>
504   <dfn><u>&gamma;</u></dfn>: mapping from capture variables to
505   values<br/>
506 </p>
507 <div style="padding:0em 1em 0em; text-align:justify;background:white;">
508   <div class="infer">
509     <span> v &in; &lbrack; t &rbrack;</span>
510     <span>&sigma;; &delta; &vdash; v / t &rleadsto; &emptyset;,
511       &sigma;</span>
512   </div><span>(type)</span>
513
514   <div class="infer">
515     <span></span>
516     <span>&sigma; &vdash; v / ẋ &rleadsto; &emptyset;,
517       &sigma;[ ẋ := Op(ẋ) (v, &sigma;(ẋ)) ]</span>
518   </div><span>(acc)</span>
519
520   <div class="infer">
521     <span></span>
522     <span>&sigma; &vdash; v / x &rleadsto; { x &mapsto; v },
523       &sigma;</span>
524   </div><span>(var)</span>
525
526   <div class="infer">
527     <span>&sigma; &vdash; (fst v)/p<sub>1</sub>
528     &rleadsto; &gamma;<sub>1</sub>, &sigma;' </span>
529     <span>&sigma;' &vdash; (snd v)/p<sub>2</sub> 
530       &rleadsto; &gamma;<sub>2</sub>, &sigma;''
531     </span>
532     <span>&sigma; &vdash; v /
533       (p<sub>1</sub>, p<sub>2</sub>)  &rleadsto;
534       &gamma;<sub>1</sub>&cup; &gamma;<sub>2</sub>,
535       &sigma;''</span>
536   </div><span>(pair)</span>  <span class="fill"></span>
537 <span style="position:relative;top:-1em;">Remember, if <dfn>v ≡ (v1,v2)<sub>&delta;</sub></dfn> then <dfn><tt>fst v</tt> ≡ v<sub>1 &left;v · &delta;</sub></dfn> and <dfn><tt>snd v</tt> ≡ v<sub>2 &right;v · &delta;</sub></dfn><br/>
538 (some other rules for alternation, failure, recursion, <i>etc.</i>)</span>
539 </div>
540 </div>
541 <div class="sws-slide">
542   <h1>Typing of patterns (with accumulators) 1/2</h1>
543   <p>Well known that typing path expressions escapes regular tree languages
544     (i.e. &cduce;'s types). Consider:
545   </p>
546 <pre style="margin:-3em 0pt -1em;">
547       t ≡ <tt>&lt;c&gt;[ <u>&lt;a&gt;[]</u> t <u>&lt;b&gt;[]</u> ] </tt>   &lor;   <tt>&lt;c&gt;[]</tt>   <img style="margin-left:3em;width:15%;vertical-align:middle;" src="anbn_tree.svg" alt="anbn"/>
548 </pre>
549 <p>The set of all <tt><u>a</u></tt> or <tt><u>b</u></tt> labeled
550   descendants
551   is <dfn>{ <tt>[<u>&lt;a&gt;[]</u></tt><sup>n</sup> <tt><u>&lt;b&gt;[]</u></tt><sup>n</sup> <tt>]</tt>  | n ≥ 0 }</dfn>
552 which is not a type.</p>
553 <p> Intuitively it means that when applying a
554   recursive pattern against a recursive type, we may generate an
555   <s>infinite number of distinct types</s> for an accumulator.
556 </p>
557 </div>
558 <div class="sws-slide">
559   <h1>Typing of patterns (with accumulators) 2/2</h1>
560   <p>We use the typing relation of operators to introduce
561   approximations:</p>
562   <pre>
563     <u>t<sub>0</sub></u>, <tt>[</tt> (t<sub>1</sub> &lor; … &lor; t<sub>n</sub>)<tt>* ]</tt> &rarrow;<sup>cons</sup> <tt>[</tt> (<u>t<sub>0</sub></u> &lor; t<sub>1</sub> &lor; … &lor; t<sub>n</sub>)<tt>* ]</tt> <br/>
564     <u>t<sub>0</sub></u>, <tt>[</tt> (t<sub>1</sub> &lor; … &lor; t<sub>n</sub>)<tt>* ]</tt> &rarrow;<sup>snoc</sup> <tt>[</tt> (<u>t<sub>0</sub></u> &lor; t<sub>1</sub> &lor; … &lor; t<sub>n</sub>)<tt>* ]</tt>
565   </pre>
566   <p>Ensures termination of typechecking of patterns.</p>
567 </div>
568 <div class="sws-slide">
569   <h1>Results</h1>
570 <p>Zippers (in values, types, patterns) are a conservative extension</p>
571 <ul>
572   <li><u>Subtyping and typechecking</u> are extended straightforwardly</li>
573   <li>Typing of patterns introduces <u>sound approximations</u> only for accumulators</li>
574   <li>Provided the operators are sound, the whole language remains <u>type-safe</u></li>
575 </ul>
576 </div>
577 <div class="sws-slide">
578 <h1>Downward XPath axes</h1>
579 <pre style="background:white">     <tt>self ::</tt> t ≡    (ẋ <tt>&amp;</tt> t | _ )<sub>&ztop;</sub>                                (Init(ẋ) = [], Op(ẋ) = <tt>snoc</tt>)
580
581      <span class="sws-pause"><tt>child ::</tt> t ≡  <tt>&lt;_&gt;[</tt> (ẋ <tt>&amp;</tt> t | _ )<tt>* ]</tt><sub>&ztop;</sub></span>
582 </pre>
583 <p class="sws-pause">Example: applying <tt><u>child::&lt;b&gt;_</u></tt>   to the document</p>
584 <code>      &lt;doc&gt;[ &lt;a&gt;[]    &lt;b&gt;[]    &lt;c&gt;[]    &lt;b&gt;[] ]<sub>&bcirc;</sub>
585         <span class="sws-pause">&lt;_&gt;[  <span class="sws-pause"> _</span>    <mark class="sws-pause">(ẋ &amp; &lt;b&gt;_)</mark>   <span>_</span>     <mark>(ẋ &amp; &lt;b&gt;_)</mark>]<sub >&ztop;</sub></span>
586
587         <span class="sws-pause"> ẋ&mapsto; [ &lt;b&gt;[]<sub>&left;… &right;… &right;… &bcirc;</sub>    &lt;b&gt;[]<sub>&left;… &right;… &right;… &right;… &right;… &bcirc;</sub>   ] </span>
588 </code>
589
590 <pre class="sws-pause">
591      <tt>descendant-or-self::</tt> t ≡   X ≡ ((ẋ <tt>&amp;</tt> t | _ ) <tt> &amp; </tt> (<tt>&lt;_&gt;[</tt> X <tt>* ]</tt>)<sub>&ztop;</sub> | _ )
592
593      <tt>descendant</tt> :: t ≡ <tt>&lt;_&gt;[ (descendant-or-self::</tt>t<tt>)* ]</tt><sub>&ztop;</sub>
594 </pre>
595 <!--
596 <script type="text/javascript">
597 /* <![CDATA[ */
598   var svgDoc = null;
599
600   function reset () {
601         svgDoc = svgDoc || document.getElementById("svgRBTree").contentDocument;
602         var f = svgDoc.getElementById("nodef");
603         f.style['fillOpacity'] = "0";
604         var elems = svgDoc.getElementsByClassName("parentf");
605         for(var i = 0; i < elems.length; i++) {
606             elems[i].style['strokeWidth'] = '2px';
607        };
608   };
609
610   reg (0, function (c) {
611          console.log(0);
612          reset();
613   });
614
615   reg (1, function (c) {
616          console.log(1);
617          var f = svgDoc.getElementById("nodef");
618          console.log(' Opacity ' + f.style['fillOpacity']);
619          f.style['fillOpacity'] = "0.5";
620          console.log(' Opacity ' + f.style['fillOpacity']);
621      });
622
623   reg (2, function (c) {
624          console.log(2);
625         var elems = svgDoc.getElementsByClassName("parentf");
626         for(i = 0; i < elems.length; i++) {
627              elems[i].style['strokeWidth'] = '6px';
628           }
629      });
630    reg (3, function (c) {          console.log(3); reset(); });
631 /*]]>*/
632 </script>
633 -->
634 </div>
635 <div class="sws-slide">
636   <h1>Binary-tree encoding</h1>
637   <p>We use  <u>regular expressions</u> over basic &left;/&right; zippers to encode upward XPath</p>
638 <code style="width:50%;float:left;">   <![CDATA[<a>[ <b>[
639           <c>[]
640           <d>[]
641           <e>[ <f> [] ]
642         ]
643    ]]]>
644 </code><img style="width:17.5%;" src="ex_ntree.svg" alt="ex_ntree" /><br/>
645 <p class="sws-pause"><img style="margin-top:-1em;margin-left:5%;width:85%;" src="rb_tree.svg" alt="rb_tree"/></p>
646 </div>
647
648 <div class="sws-slide">
649 <h1>Upward XPath axes</h1>
650 <div style="position:absolute; width:80%; left:10%;top:15%">
651 <object id="svgRBTree" data="rb_tree.svg" type="image/svg+xml" style="z-index:1;position:absolute;width:100%"  />
652 <object class="sws-onframe-1" id="svgRBTree1" data="rb_tree01.svg" type="image/svg+xml" style="z-index:1;position:absolute;width:100%" />
653 <object class="sws-onframe-2" id="svgRBTree2" data="rb_tree02.svg" type="image/svg+xml" style="z-index:3;position:absolute;width:100%"  />
654 <object class="sws-onframe-3" id="svgRBTree3" data="rb_tree03.svg" type="image/svg+xml" style="z-index:4;position:absolute;width:100%"  />
655 <object class="sws-onframe-4" id="svgRBTree4" data="rb_tree04.svg" type="image/svg+xml" style="z-index:5;position:absolute;width:100%"  />
656 </div>
657 <pre style="position:absolute;bottom:5%;z-index:1;">     <tt>parent ::</tt> t ≡   &top;<sub> (&left;_) · (&right;_)* · (&right; ẋ &amp; t) · (( (&left; _) · &ztop;)  &lor;  &bcirc; )</sub>
658                                              
659 <span class="sws-onframe-5">     <tt>ancestor ::</tt> t ≡   &top;<sub> ( (&left;_) · (&right;_)* · (&right; ẋ &amp; t) )* · &bcirc; </sub></span>
660
661
662
663
664 </pre>
665 <pre style="position:absolute;bottom:5%;z-index:2;">
666
667                                   <span class="sws-onframe-1" style="font-size:110%;color:#1fb01b;">⬆</span> <span class="sws-onframe-2" style="font-size:110%;color:#1fb01b;">⬆</span>     <span class="sws-onframe-3" style="font-size:110%;color:#1fb01b;">⬆</span>     <span class="sws-onframe-4" style="font-size:110%;color:#1fb01b;">⬆</span>
668
669                                            <span class="sws-onframe-5" style="color:#1fb01b;border-color:#1fb01b;border-top-style:dashed;border-top-width:3pt;position:relative;top:0.5em;">         parent         </span>
670
671
672
673 </pre>
674 </div>
675 <div class="sws-slide">
676   <h1>Other results</h1>
677 <ul>
678   <li>Encoding of paths is compositional</li>
679   <li>Once we have paths, translation from XQuery to &cduce; is straightforward</li>
680   <li>We also give a direct typing algorithm for XQuery 3.0 rather than typing the translation to &cduce;</li>
681 </ul>
682 </div>
683 <div class="sws-slide">
684 <h1>Conclusion, thoughts and future work</h1>
685 <ul>
686   <li>Adding path expressions to a functional language such as &cduce; is possible </li>
687   <li>Semantic subtyping and regular expression types play nicely with zippers</li>
688   <li>In terms of language design, exposing directly zippers to the programmer (still need work at the syntax level)</li>
689   <li>Implementation on-going (including a &cduce; to javascript backend)</li>
690   <li>Extend the approach to Json (google ``path language for json´´), i.e. generalise from products to extensible records</li>
691 </ul>
692 <p class="sws-pause" style="text-align:center;"><b><u>Thank you!</u></b></p>
693 </div>
694
695   </body>
696 </html>