.
[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   "𝟘" >
18           <!ENTITY top      "𝟙" >
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         CNRS, PPS, Université Paris-Diderot, Paris, France <br/>
193         Kangwon National University, Chuncheon, Rep. of Korea<br/>
194         LRI, Université Paris-Sud, Orsay, France
195       </p>
196     </div>
197     <div class="sws-slide">
198       <h1>XQuery 3.0</h1>
199       <p>W3C standard language for querying XML
200       databases/documents</p>
201 <code style="background:white">
202    declare function <u>get_links</u>(<u>$page</u>, <u>$print</u>) {
203
204        <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>
205        <span class="for">return</span> <u>print</u>(<u>$i</u>)
206    }
207
208    declare function <u>pretty</u>(<u>$link</u>) {
209        <span class="ts">typeswitch</span>(<u>$link</u>)
210            <span class="ts">case</span> <u>$l</u> <span class="ts">as element(a)</span>
211               return <span class="sw">switch</span> (<u>$l</u><span class="xpath">/@class</span>)
212                  <span class="sw">case</span> "style1"
213                      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;
214                  default return <u>$l</u>
215
216            <span class="ts">default return</span> <u>$link</u>
217    }
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 (ML-style) equipped with
250       semantic subtyping</p>
251
252 <code>
253   let <u>pretty</u> (&lt;a&gt;_ -&gt; &lt;a&gt;_  &amp;  Any\&lt;a&gt;_ &rarrow; Any\&lt;a>_)
254
255     | &lt;a class="style1" href=<u>h</u> ..&gt; <u>l</u> &rarrow; &lt;a href=<u>h</u>&gt;[ &lt;b&gt;<u>l</u> ]
256     | x &rarrow; x
257
258
259   let <u>get_links</u> (page: &lt;_&gt;_) (print: &lt;a&gt;_ -&gt; &lt;a&gt;_) : [ &lt;a&gt;_ * ] =
260
261       match page with
262       &lt;a&gt;_ &amp; x &rarrow; [ (print x) ]
263     | &lt; (_\‘b) &gt; l &rarrow;
264                  (transform l with (i &amp; &lt;_&gt;_) &rarrow; get_links i print)
265     | _ -&gt; [ ]
266
267
268
269
270 </code>
271
272
273     </div>
274     <div class="sws-slide">
275       <h1>&cduce;</h1>
276       <ul>
277         <li>Pros<br/>
278           + Statically typed <br/>
279           + compact (and efficient) type and value pattern-matching
280         </li>
281         <li>Cons<br/>
282           - <s>complex navigation encoded through recursion</s>
283           - no type inference for functions
284         </li>
285       </ul>
286       <p>Writing functions to traverse documents is painfull</p>
287     </div>
288     <div class="sws-slide">
289       <h1>This work</h1>
290       <ol style="margin-left:1em; margin-right:0.25em;list-style-position:inside;">
291         <li id="tobox" style="padding:1em 0em 1em 0em;"><span class="lh">Add support for path navigation to
292             &cduce;</span>
293           <ul id="toshow" style="margin-top:2em;display:none;">
294             <li>Enrich the type algebra with <em>zippers</em> (à la Huet)</li>
295             <li>Extend pattern-matching construct to <em>zipped values  and types</em></li>
296             <li>Encode path expressions as recursive patterns</li>
297           </ul>
298         </li>
299         <li style="padding:1em 0em 1em 0em;">Perform a type-directed translation from XQuery to
300           &cduce;</li>
301
302       </ol>
303       <script type="text/javascript">
304         reg ("0", col_change(".lh",""));
305         reg ("1", col_change(".lh", "#f80"));
306
307         reg ("2", function (canvas) { $("#toshow").show(); });
308         reg ("3", function (c) { $("#tobox").css (
309         { 'background' : '#dfd', 'border-radius': '1em' });});
310       </script>
311     </div>
312     <div class="sws-slide">
313       <h1>&cduce;'s type algebra</h1>
314 <pre>
315     t ::=  b  |  c  |  t × t  |  t &rarrow; t  |  t &lor; t  |  t  &land; t  |  t &setminus; t  |  &top;  |  &bottom;  |  &alpha;
316 </pre>
317 <p><dfn>b</dfn> : ranges over basic types (<tt>Int</tt>, <tt>String</tt>, …)<br/>
318    <dfn>c</dfn> : ranges over singleton types
319    (<tt>`A</tt>, <tt>42</tt>, …)<br/>
320    <dfn>&alpha;</dfn> : type variables<br/>
321    types are interpreted co-inductively (recursive types) and regular
322    expression types<br/>
323 </p>
324 <pre>
325     t<sub>1</sub> ≡ (<tt>Int</tt> × t<sub>1</sub>) &lor; t<sub>2</sub>
326     t<sub>2</sub> ≡ (<tt>Bool</tt> × t<sub>2</sub>) &lor; (<tt>Bool</tt> × <tt>`nil</tt>)
327
328     <span class="sws-pause">t<sub>1</sub> ≡ <tt>[ Int* Bool+ ]</tt></span>
329
330 </pre>
331     </div>
332     <div class="sws-slide">
333       <h1>Semantic subtyping</h1>
334 <pre style="text-align:center;">
335 t &leq; s   &Lrarrow;   &lbrack;t&rbrack; &subseteq;  &lbrack;s&rbrack;
336 </pre>
337 <p><dfn>&lbrack; &rbrack;</dfn> interpretation of types as sets of
338   values<br/>
339   Allows to reason <i>modulo</i> semantic equivalence of type connectives :
340 </p>
341 <pre >
342       <tt>[ Int* (Int | Bool*)? ]</tt> &land; <tt>[ Int+ (Bool+ | Int)* ]</tt> ≡ <tt>[Int+ Bool*]</tt>
343 </pre>
344 </div>
345 <div class="sws-slide">
346       <h1>&cduce; patterns</h1>
347 <pre style="text-align:center;">    p ::=  t  |  p | p  |  p &amp; p  | (p, p) |  x   </pre>
348 <p><dfn>t</dfn> ranges over types<br/>
349   <dfn>x</dfn> ranges over capture variables<br/>
350   patterns are also co-inductively interpreted (recursive patterns)
351 </p>
352 <p><dfn><u>v / p</u></dfn> : matching a value against a pattern yields a
353   substitution from variables to values<br/>
354    <dfn><u>&lbag; p &rbag;</u></dfn> : the set of values accepted by a
355    pattern is <u>a type</u><br/>
356    <dfn><u> t / p</u></dfn> : matching a type against a pattern yields a
357    substitution from variables to types<br/>
358 </p>
359 </div>
360 <div class="sws-slide">
361       <h1>&cduce; patterns (example)</h1>
362 <p>Assume <tt><u>l</u></tt> has type <tt>[ Int+ Bool* ]</tt>,  consider:</p>
363 <code>
364        match <u>l</u> with
365        [ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ] &rarrow;  (<u>x</u>, <u>y</u>)
366     |  [ _* (<u>x</u> &amp; Int) ]                  &rarrow;  (<u>x</u>, `false)
367     |  [ ]                               &rarrow;  (0, `false)
368 </code>
369 <ol>
370 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ]</tt>&rbag; ≡ <tt>[ &top;* Int Bool+ ]</tt></dfn><br/>
371   yield : { x &mapsto; <tt>Int</tt>, y &mapsto; <tt>Bool</tt> }
372 </li>
373 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) ]</tt>&rbag; ≡ <tt>[ &top;* Int ]</tt></dfn><br/>
374   yield : { x &mapsto; <tt>Int</tt> }
375 </li>
376 <li>Since <dfn><tt>[Int+ Bool* ]</tt> &setminus; ( <tt>[ &top;* Int Bool+ ]</tt> &lor;  <tt>[ &top;* Int]</tt>) ≡ &bottom;  </dfn>
377     the third case is unreachable.
378 </li>
379
380
381 </ol>
382
383 </div>
384 <div class="sws-slide">
385 <h1>&cduce; data-model</h1>
386 <p>Sequences are nested pairs: <dfn><tt>[</tt> v<sub>1</sub>  … v<sub>n</sub> <tt>]</tt> ≡ (v<sub>1</sub>, (…, (v<sub>n</sub>, <tt>`nil</tt>)))
387 </dfn></p>
388 <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>
389 </p>
390 <p>Ususal lisp-like encoding of trees, how to perform navigation
391   (including upward ?)</p>
392 </div>
393 <div class="sws-slide">
394 <h1>Zippers (1/2)</h1>
395 <ul>
396   <li>Introduced in 1997 by Gérard Huet</li>
397   <li>Stack of visited</li>
398   <li>Push the current node on the stack when descending</li>
399   <li>Put the top of the stack and pop it to go backward</li>
400   <li>Tag the elements of the stack to remember which of a node we
401   have visited</li>
402 </ul>
403 <pre style="text-align:center;"> v ::=  …  |  v<sub>&delta;</sub>
404  &delta; ::=  &bcirc;  | &left;v · &delta; | &right;v · &delta;
405 </pre>
406
407 </div>
408 <div class="sws-slide">
409 <h1>Zippers (2/2)</h1>
410 <p><tt><u>fst</u></tt> (resp. <tt><u>snd</u></tt>) takes the first (resp. second)
411   projection of a pair and update its zipper accordingly:</p>
412 <pre>    v<sub>1</sub> ≡ (1, (2, (3, (4, `nil))))<sub>&bcirc;</sub>
413     v<sub>11</sub> ≡ fst v<sub>1</sub> ≡ 1<sub>&left;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
414     v<sub>2</sub> ≡ snd v<sub>1</sub> ≡ (2, (3, (4, `nil)))<sub>&right;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
415     v<sub>3</sub> ≡ snd v<sub>2</sub> ≡ (3, (4, `nil))<sub>&right;v<sub>2</sub> · &right;v<sub>1</sub> · &bcirc; </sub>
416 </pre>
417 <p><tt><u>up</u></tt> pops returns the head of the zipper: </p>
418 <pre>    up v<sub>3</sub> ≡ v<sub>2</sub> ≡ (2, (3, (4, `nil)))<sub>&right;(1, (2, (3, (4, `nil))))<sub>&bcirc;</sub> · &bcirc; </sub>
419 </pre>
420 </div>
421 <div class="sws-slide">
422   <h1>Zipper types</h1>
423 <p>We extend the type-algebra with zipper types:</p>
424 <pre style="text-align:center;"> t ::=  …  |  t<sub>&tau;</sub>
425  &tau; ::=  &bcirc;  |  &left;t · &tau;  | &right;t · &tau;  |  &tau; &lor; &tau;  |  &tau; &setminus; &tau;  |  &ztop;
426 </pre>
427 <p><dfn>&bcirc;</dfn>: singleton type denoting the empty zipper<br/>
428    <dfn>&ztop;</dfn>: the top zipper types<br/>
429    Zipper types are interpreted co-inductively (regular expressions on
430    zippers)<br/><br/>
431    <dfn><tt>Int</tt><sub>(&left;&top;)* &bcirc;</sub></dfn>: type of
432    integers that are the leftmost descendant of a tree.<br/>
433    <dfn><tt><![CDATA[<html>[ <head>[…] <body>[…] ]]]></tt><sub>&bcirc;</sub></dfn>: type of
434    HTML documents<br/>
435    <dfn><tt><![CDATA[<a href=String>[ … ]]]></tt><sub>&ztop;</sub></dfn>: types of links in any context
436
437 </p>
438 </div>
439 <div class="sws-slide">
440 <h1>Tree navigation</h1>
441 <p>Since patterns contain types, we can check complex
442   conditions:</p>
443 <pre style="width:60%;display:inline-block;border-width:0pt 1pt 0pt 0pt; border-style:dashed;border-color: black;vertical-align:middle">
444     p ≡ <tt id="test">&lt;a&gt;_</tt>   &lor;   <tt>&lt;_&gt;[ _* p _* ]</tt>
445  
446     &tau; ≡ &bcirc;   &lor;   &right;&top; · &tau;   &lor;   &left;(&top;&setminus; <tt>&lt;b&gt;_</tt>) · &tau; 
447
448 </pre>
449 <code style="width:20%;display:inline-block;vertical-align:middle">
450     match <u>v</u> with
451        <dfn>p<sub>&tau;</sub></dfn> &amp; <u>x</u> &rarrow; …
452    | _        &rarrow; …
453 </code>
454 <p style="background:white">
455 We want more, namely return <i>all</i> descendants (ancestor,
456   children,  siblings, …) of a node matching a particular condition
457 <br/><br/>
458 Remark: (recursive) patterns <u>already perform a recursive traversal
459   of the value</u>
460 <br/><br/>
461 <em>Idea</em>: Piggy back on the traversal and <em>accumulate</em>
462 nodes in special variables
463 </p>
464 <script type="text/javascript">
465   reg (0, col_change ("#test", ""));
466   reg (1, col_change ("#test", "orange"));
467 </script>
468 </div>
469 <div class="sws-slide">
470   <h1>Operators and Accumulators</h1>
471 <p>An <u>operator</u> is a 4-tupple <dfn>(o, n<sub>o</sub>,
472     &rleadsto;<sub>o</sub>, &rarrow;<sub>o</sub>)</dfn>, where:</p>
473 <p><dfn><u>o</u></dfn>: is the accumulator name<br/>
474 <dfn><u>n<sub>o</sub></u></dfn>: is the arity of <u>o</u><br/>
475 <dfn><u>&rleadsto;<sub>o</sub></u></dfn>:
476 &mathV;<sup>n<sub>o</sub></sup> &rsarrow; &mathV;, the reduction relation <br/>
477 <dfn><u>&rarrow;<sub>o</sub></u></dfn>:
478 &mathT;<sup>n<sub>o</sub></sup> &rsarrow; &mathT;, the typing relation <br/>
479 </p>
480 <p>An <u>accumulator</u> is a variable (ranged over
481   by <u>ẋ</u>, <u>ẏ</u>, …) with:<br/><br/>
482   <dfn><u>Op(ẋ)</u></dfn>: an operator<br/>
483   <dfn><u>Init(ẋ)</u> &in; &mathV;</dfn> : an initial value<br/>
484 </p>
485 </div>
486 <div class="sws-slide">
487   <h1>Some operators</h1>
488   <pre>
489     v, v' &rleadsto;<sup>cons,</sup> (v, v') <br/>
490     v, <tt>`nil</tt> &rleadsto;<sup>snoc</sup> (v, <tt>`nil</tt>)<br/>
491     v, (v',v'') &rleadsto;<sup>snoc</sup> (v', snoc(v,v''))<br/>
492   </pre>
493 <p>Now we can use accumulators equipped with cons/snoc in
494   patterns. Instead of matching a single node against a variable, it
495   <u>accumulates</u> that node in sequence (in reverse or in-order).</p>
496 </div>
497 <div class="sws-slide">
498 <h1>Pattern matching semantics (v/p)</h1>
499 <pre style="text-align:center;">
500   &sigma;; &delta; &vdash; v / p &rleadsto; &gamma;, &sigma;'
501 </pre>
502 <p style="font-size:90%"><dfn><u>&sigma;</u>, <u>&sigma;'</u></dfn>: mapping from accumulators to
503   values<br/>
504   <dfn><u>v</u></dfn>: input value<br/>
505   <dfn><u>p</u></dfn>: pattern<br/>
506   <dfn><u>&gamma;</u></dfn>: mapping from capture variables to
507   values<br/>
508   <dfn><u>&delta;</u></dfn>: current context
509 </p>
510 <div style="padding:0em 1em 0em; text-align:justify;font-size:85%;background:white;">
511   <div class="infer">
512     <span> v &in; &lbrack; t &rbrack;</span>
513     <span>&sigma;; &delta; &vdash; v / t &rleadsto; &emptyset;,
514       &sigma;</span>
515   </div><span>(type)</span>
516
517   <div class="infer">
518     <span></span>
519     <span>&sigma;; &delta; &vdash; v / ẋ &rleadsto; &emptyset;,
520       &sigma;[ ẋ := Op(ẋ) (v<sub>&delta;</sub>, &sigma;(ẋ)) ]</span>
521   </div><span>(acc)</span>
522
523   <div class="infer">
524     <span></span>
525     <span>&sigma;; &delta; &vdash; v / x &rleadsto; { x &mapsto; v },
526       &sigma;</span>
527   </div><span>(var)</span>
528
529   <div class="infer">
530     <span>&sigma;; &left;v · &delta; &vdash; (fst v)/p<sub>1</sub>
531     &rleadsto; &gamma;<sub>1</sub>, &sigma;' </span>
532     <span>&sigma;'; &right;v · &delta; &vdash; (snd v)/p<sub>2</sub> 
533       &rleadsto; &gamma;<sub>2</sub>, &sigma;''
534     </span>
535     <span>&sigma;; &delta; &vdash; v /
536       (p<sub>1</sub>, p<sub>2</sub>)  &rleadsto;
537       &gamma;<sub>1</sub>&cup; &gamma;<sub>2</sub>,
538       &sigma;''</span>
539   </div><span>(pair)</span>  <span class="fill"></span>
540 <span>… and some other rules for alternation, failure, recursion, <i>etc.</i></span>
541 </div>
542 </div>
543 <div class="sws-slide">
544   <h1>Typing of patterns (with accumulators) 1/2</h1>
545   <p>Well known that typing path expressions escapes regular tree languages
546     (i.e. &cduce;'s types). Consider:
547   </p>
548 <pre style="margin:-3em 0pt -1em;">
549       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"/>
550 </pre>
551 <p>The set of all <tt><u>a</u></tt> or <tt><u>b</u></tt> labeled
552   descendants
553   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>
554 which is not a type.</p>
555 <p> Intuitively it means that when applying a
556   recursive pattern against a recursive type, we may generate an
557   <s>infinite number of distinct types</s> for an accumulator.
558 </p>
559 </div>
560 <div class="sws-slide">
561   <h1>Typing of patterns (with accumulators) 2/2</h1>
562   <p>We use the typing relation of operators to introduce
563   approximations:</p>
564   <pre>
565     <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/>
566     <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>
567   </pre>
568   <p>Ensures termination of typechecking of patterns.</p>
569 </div>
570 <div class="sws-slide">
571   <h1>Results</h1>
572 <p>Zippers (in values, types, patterns) are orthogonal to the rest of the language</p>
573 <ul>
574   <li><u>Subtyping and typechecking</u> are extended straightforwardly</li>
575   <li>Typing of patterns introduces <u>sound approximations</u> only for accumulators</li>
576   <li>Provided the operators are sound, the whole language remains <u>type-safe</u></li>
577 </ul>
578 </div>
579 <div class="sws-slide">
580   <h1>From zippers to XPath</h1>
581   <p>We use  <u>regular expressions</u> over basic &left;/&right; zippers to encode XPath</p>
582 <code style="width:50%;float:left;">   <![CDATA[<a>[ <b>[
583           <c>[]
584           <d>[]
585           <e>[ <f> [] ]
586         ]
587    ]]]>
588 </code><img style="width:17.5%;" src="ex_ntree.svg" alt="ex_ntree" /><br/>
589 <p class="sws-pause"><img style="margin-top:-1em;margin-left:5%;width:85%;" src="rb_tree.svg" alt="rb_tree"/></p>
590 </div>
591 <div class="sws-slide">
592 <h1>Downward axes</h1>
593 <tt>  <![CDATA[<a>[ <b>[  <c>[]  <d>[] <e>[ <f> [] ]   ]  ]]]><sub>&bcirc;</sub></tt>
594 <object id="svgRBTree" data="rb_tree.svg" type="image/svg+xml" style="margin-left:7.5%;width:85%"  />
595 <pre>
596      <tt>self ::</tt> t ≡    (ẋ <tt>&amp;</tt> t | _ )<sub>&ztop;</sub>
597      <tt>child ::</tt> t ≡  <tt>&lt;_&gt;[</tt> (ẋ <tt>&amp;</tt> t | _ )<tt>* ]</tt><sub>&ztop;</sub>
598      <tt>descendant-or-self::</tt> t ≡   X ≡ ((ẋ <tt>&amp;</tt> t | _ ) <tt> &amp; &lt;_&gt;[</tt> X <tt>* ]</tt>)<sub>&ztop;</sub>
599      <tt>descendant</tt> :: t ≡ <tt>&lt;_&gt;[ (descendant-or-self::</tt>t<tt>)* ]</tt><sub>&ztop;</sub>
600 </pre>
601 <!--
602 <script type="text/javascript">
603 /* <![CDATA[ */
604   var svgDoc = null;
605
606   function reset () {
607         svgDoc = svgDoc || document.getElementById("svgRBTree").contentDocument;
608         var f = svgDoc.getElementById("nodef");
609         f.style['fillOpacity'] = "0";
610         var elems = svgDoc.getElementsByClassName("parentf");
611         for(var i = 0; i < elems.length; i++) {
612             elems[i].style['strokeWidth'] = '2px';
613        };
614   };
615
616   reg (0, function (c) {
617          console.log(0);
618          reset();
619   });
620
621   reg (1, function (c) {
622          console.log(1);
623          var f = svgDoc.getElementById("nodef");
624          console.log(' Opacity ' + f.style['fillOpacity']);
625          f.style['fillOpacity'] = "0.5";
626          console.log(' Opacity ' + f.style['fillOpacity']);
627      });
628
629   reg (2, function (c) {
630          console.log(2);
631         var elems = svgDoc.getElementsByClassName("parentf");
632         for(i = 0; i < elems.length; i++) {
633              elems[i].style['strokeWidth'] = '6px';
634           }
635      });
636    reg (3, function (c) {          console.log(3); reset(); });
637 /*]]>*/
638 </script>
639 -->
640 </div>
641 <div class="sws-slide">
642 <h1>Upward axes</h1>
643 <tt>  <![CDATA[<a>[ <b>[  <c>[]  <d>[] <e>[ <f> [] ]   ]  ]]]><sub>&bcirc;</sub></tt>
644 <object id="svgRBTree" data="rb_tree.svg" type="image/svg+xml" style="margin-left:7.5%;width:85%"  />
645 <pre>
646      <tt>parent ::</tt> t ≡   &top;<sub> (&left;_) · (&right;_)* · (&right; ẋ &amp; t) · (( (&left; _) · &ztop;)  &lor;  &bcirc; )</sub>
647      <tt>ancestor ::</tt> t ≡   &top;<sub> ((&left;_) · (&right;_)* · (&right; ẋ &amp; t))* · &bcirc; </sub>
648 </pre>
649 </div>
650 <div class="sws-slide">
651   <h1>Other results</h1>
652 <ul>
653   <li>Encoding of paths is compositional</li>
654   <li>Once we have path, translation from XQuery to &cduce; is straightforward</li>
655   <li>We also give a direct typing algorithm for XQuery 3.0 rather than typing the translation to &cduce;</li>
656 </ul>
657 </div>
658 <div class="sws-slide">
659 <h1>Conclusion, thoughts and future work</h1>
660 <ul>
661   <li>Adding path expressions to a functional language such as &cduce; is possible </li>
662   <li>Semantic subtyping and regular expression types play nicely with zippers</li>
663   <li>In terms of language design, exposing directly zippers patterns to the programmer is a big no-no</li>
664   <li>Can also be applied to XSLT</li>
665   <li>Implementation on-going (including a &cduce; to javascript backend)</li>
666   <li>Extend the approach to Json (google ``path language for json''), i.e. generalise from products to extensible records</li>
667 </ul>
668
669 </div>
670
671   </body>
672 </html>