.
[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         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>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><br/>
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 style="margin-top:2em;">
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 class="ll" style="padding:1em 0em 1em 0em;">Perform a type-directed translation from XQuery to
300           &cduce;</li>
301       </ol>
302       <script type="text/javascript">
303         reg (1, col_change(".lh", "#f83"));
304         reg (1, col_change(".ll", "#bbb"));
305       </script>
306     </div>
307     <div class="sws-slide">
308       <h1>&cduce;'s type algebra</h1>
309 <pre>
310     t ::=  b  |  c  |  <u>t × t</u>  |  <u>t &rarrow; t</u>  |  <a>t &lor; t</a>  |  <mark>t  &land; t</mark>  |  <mark>t &setminus; t</mark>  |  <mark>&top;</mark>  |  <mark>&bottom;</mark>  |  &alpha;
311 </pre>
312 <p><dfn>b</dfn> : ranges over basic types (<tt>Int</tt>, <tt>String</tt>, …)<br/>
313    <dfn>c</dfn> : ranges over singleton types
314    (<tt>`A</tt>, <tt>42</tt>, …)<br/>
315    <u>Type constructors</u> <br/>
316    <mark>Boolean connectives</mark> <br/>
317    <dfn>&alpha;</dfn> : type variables<br/>
318    types are interpreted co-inductively: recursive types and regular
319    expression types<br/>
320 </p>
321 <div style="vertical-align:top;">
322 <pre style="width:50%;display:inline-block;">      t<sub>1</sub> ≡ (<tt>Int</tt> × t<sub>1</sub>)    &lor;    t<sub>2</sub>
323       t<sub>2</sub> ≡ (<tt>Bool</tt> × t<sub>2</sub>)  &lor; (<tt>Bool</tt> × <tt>`nil</tt>)
324 </pre>
325 <pre style="width:30%;display:inline-block;"> <span class="sws-pause">t<sub>1</sub> ≡ <tt>[ Int* Bool+ ]</tt></span></pre>
326 </div>
327     </div>
328     <div class="sws-slide">
329       <h1>Semantic subtyping</h1>
330 <pre style="text-align:center;">
331 t &leq; s   &Lrarrow;   &lbrack;t&rbrack; &subseteq;  &lbrack;s&rbrack;
332 </pre>
333 <p><dfn>&lbrack; &rbrack;</dfn> interpretation of types as sets of
334   values<br/>
335   Allows to reason <i>modulo</i> semantic equivalence of type connectives :
336 </p>
337 <pre >
338       <tt>[ Int* (Int | Bool*)? ]</tt> &land; <tt>[ Int+ (Bool+ | Int)* ]</tt> ≡ <tt>[Int+ Bool*]</tt>
339 </pre>
340 </div>
341 <div class="sws-slide">
342 <h1>&cduce; data-model</h1>
343 <p>The usual sets of values: constants, &lambda;-abstractions, pairs, …</p>
344 <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>)))
345 </dfn></p>
346 <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>
347 </p>
348 <p>(Sometimes we write <tt>[ ]</tt> for the variant <tt>`nil</tt>)</p>
349 </div>
350 <div class="sws-slide">
351       <h1>&cduce; patterns</h1>
352 <p><i>(a.k.a. the left-hand side of an arrow in a match … with)</i></p>
353 <pre style="text-align:center;">    p ::=  t  | x | <u>(p, p)</u> |  <mark>p | p</mark>  |  <mark>p &amp; p</mark>    </pre>
354 <p><dfn>t</dfn> ranges over types<br/>
355   <dfn>x</dfn> ranges over capture variables<br/>
356   <u>Pair patterns</u><br/>
357   <mark> Alternation |, Intersection &amp;</mark><br/>
358   patterns are also co-inductively interpreted (recursive patterns)
359 </p>
360 <p><dfn><u>v / p</u></dfn> : matching a value against a pattern yields a
361   substitution from variables to values<br/>
362    <dfn><u>&lbag; p &rbag;</u></dfn> : the set of values accepted by a
363    pattern is <u>a type</u><br/>
364    <dfn><u> t / p</u></dfn> : matching a type against a pattern yields a
365    substitution from variables to types<br/>
366 </p>
367 </div>
368 <div class="sws-slide">
369       <h1>&cduce; patterns (example)</h1>
370 <p>Assume <tt><u>l</u></tt> has type <tt>[ Int+ Bool* ]</tt>,  consider:</p>
371 <code>
372        match <u>l</u> with
373        [ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ] &rarrow;  (<u>x</u>, <u>y</u>)
374     |  [ _* (<u>x</u> &amp; Int) ]                  &rarrow;  (<u>x</u>, `false)
375     |  [ ]                               &rarrow;  (0, `false)
376 </code>
377 <ol>
378 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) Bool* (<u>y</u> &amp; Bool) ]</tt>&rbag; ≡ <tt>[ &top;* Int Bool+ ]</tt></dfn><br/>
379   yield : { x &mapsto; <tt>Int</tt>, y &mapsto; <tt>Bool</tt> }
380 </li>
381 <li><dfn>&lbag;<tt>[ _* (<u>x</u> &amp; Int) ]</tt>&rbag; ≡ <tt>[ &top;* Int ]</tt></dfn><br/>
382   yield : { x &mapsto; <tt>Int</tt> }
383 </li>
384 <li>Since <dfn><tt>[Int+ Bool* ]</tt> &setminus; ( <tt>[ &top;* Int Bool+ ]</tt> &lor;  <tt>[ &top;* Int]</tt>) ≡ &bottom;  </dfn>
385     the third case is unreachable.
386 </li>
387
388
389 </ol>
390
391 </div>
392
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 nodes</li>
398   <li>Push the current node on the stack when traversing a pair</li>
399   <li>Take top of the stack to go backward</li>
400   <li>Tag the elements of the stack to remember which component of a
401   pair we 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> 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 (root element)<br/>
428    <dfn>&ztop;</dfn>: the top zipper type<br/>
429    Zipper types are interpreted co-inductively<br/><br/>
430    <dfn><tt>Int</tt><sub>(&left;&top;)* &bcirc;</sub></dfn> <span style="float:right;">type of
431    integers that are the leftmost descendant of a tree</span><br/><br/>
432    <dfn><tt><![CDATA[<html>[ <head>[…] <body>[…] ]]]></tt><sub>&bcirc;</sub></dfn> <span style="float:right;">type of
433    HTML documents</span><br/><br/>
434    <dfn><tt><![CDATA[<a href=String>[ … ]]]></tt><sub>(&right; &top;) · &ztop;</sub></dfn> <span style="float:right;">types of links in any context</span>
435
436 </p>
437 </div>
438 <div class="sws-slide">
439 <h1>Tree navigation</h1>
440 <p>Since patterns contain types, we can check complex
441   conditions:</p>
442 <pre style="width:60%;display:inline-block;border-width:0pt 1pt 0pt
443   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>
444     p ≡ <tt id="test">&lt;a&gt;_</tt>   &lor;   <tt>&lt;_&gt;[ _* p _* ]</tt>
445  
446   <span style="font-family:'Open Sans';">Deos not have an ancestor <tt>&lt;b&gt;_</tt>:</span>
447     &tau; ≡ &bcirc;   &lor;   &right;(&top;&setminus; <tt>&lt;b&gt;_</tt>) · &tau;   &lor;   &left;(&top;&setminus; <tt>&lt;b&gt;_</tt>) · &tau; 
448
449 </pre>
450 <code style="width:20%;display:inline-block;vertical-align:middle">
451     match <u>v</u> with
452        <dfn>p<sub>&tau;</sub></dfn> &amp; <u>x</u> &rarrow; …
453    | _        &rarrow; …</code>
454 <p style="background:white">We want more, namely return <i>all</i> descendants (ancestors,
455   children,  siblings, …) of a node matching a particular condition
456 <br/><br/>
457 Remark: (recursive) patterns <u>already perform a recursive traversal
458   of the value</u>
459 <br/>
460 <em>Idea</em>: Piggy back on the traversal and <em>accumulate</em>
461 nodes in special variables
462 </p>
463 </div>
464 <div class="sws-slide">
465   <h1>Operators and Accumulators</h1>
466 <p>An <u>operator</u> is a 4-tupple <dfn>(o, n<sub>o</sub>,
467     &rleadsto;<sub>o</sub>, &rarrow;<sub>o</sub>)</dfn>, where:</p>
468 <p><dfn><u>o</u></dfn>: is the accumulator name<br/>
469 <dfn><u>n<sub>o</sub></u></dfn>: is the arity of <u>o</u><br/>
470 <dfn><u>&rleadsto;<sub>o</sub></u></dfn>:
471 &mathV;<sup>n<sub>o</sub></sup> &rsarrow; &mathV;, the reduction relation <br/>
472 <dfn><u>&rarrow;<sub>o</sub></u></dfn>:
473 &mathT;<sup>n<sub>o</sub></sup> &rsarrow; &mathT;, the typing relation <br/>
474 </p>
475 <p>An <u>accumulator</u> is a variable (ranged over
476   by <u>ẋ</u>, <u>ẏ</u>, …) with:<br/><br/>
477   <dfn><u>Op(ẋ)</u></dfn>: an operator<br/>
478   <dfn><u>Init(ẋ)</u> &in; &mathV;</dfn> : an initial value<br/>
479 </p>
480 </div>
481 <div class="sws-slide">
482   <h1>Some operators</h1>
483   <pre>
484     v, v' &rleadsto;<sup>cons,</sup> (v, v') <br/>
485     v, <tt>`nil</tt> &rleadsto;<sup>snoc</sup> (v, <tt>`nil</tt>)<br/>
486     v, (v',v'') &rleadsto;<sup>snoc</sup> (v', snoc(v,v''))<br/>
487   </pre>
488 <p>Now we can use accumulators equipped with cons/snoc in
489   patterns. Instead of matching a single node against a variable, it
490   <u>accumulates</u> that node in sequence (in reverse or in-order).</p>
491 </div>
492 <div class="sws-slide">
493 <h1>Pattern matching semantics (v/p)</h1>
494 <pre style="text-align:center;">
495   &sigma;; &delta; &vdash; v / p &rleadsto; &gamma;, &sigma;'
496 </pre>
497 <p style="font-size:90%"><dfn><u>&sigma;</u>, <u>&sigma;'</u></dfn>: mapping from accumulators to
498   values<br/>
499   <dfn><u>v</u></dfn>: input value<br/>
500   <dfn><u>p</u></dfn>: pattern<br/>
501   <dfn><u>&gamma;</u></dfn>: mapping from capture variables to
502   values<br/>
503   <dfn><u>&delta;</u></dfn>: current context
504 </p>
505 <div style="padding:0em 1em 0em; text-align:justify;font-size:85%;background:white;">
506   <div class="infer">
507     <span> v &in; &lbrack; t &rbrack;</span>
508     <span>&sigma;; &delta; &vdash; v / t &rleadsto; &emptyset;,
509       &sigma;</span>
510   </div><span>(type)</span>
511
512   <div class="infer">
513     <span></span>
514     <span>&sigma;; &delta; &vdash; v / ẋ &rleadsto; &emptyset;,
515       &sigma;[ ẋ := Op(ẋ) (v<sub>&delta;</sub>, &sigma;(ẋ)) ]</span>
516   </div><span>(acc)</span>
517
518   <div class="infer">
519     <span></span>
520     <span>&sigma;; &delta; &vdash; v / x &rleadsto; { x &mapsto; v },
521       &sigma;</span>
522   </div><span>(var)</span>
523
524   <div class="infer">
525     <span>&sigma;; &left;v · &delta; &vdash; (fst v)/p<sub>1</sub>
526     &rleadsto; &gamma;<sub>1</sub>, &sigma;' </span>
527     <span>&sigma;'; &right;v · &delta; &vdash; (snd v)/p<sub>2</sub> 
528       &rleadsto; &gamma;<sub>2</sub>, &sigma;''
529     </span>
530     <span>&sigma;; &delta; &vdash; v /
531       (p<sub>1</sub>, p<sub>2</sub>)  &rleadsto;
532       &gamma;<sub>1</sub>&cup; &gamma;<sub>2</sub>,
533       &sigma;''</span>
534   </div><span>(pair)</span>  <span class="fill"></span>
535 <span>… and some other rules for alternation, failure, recursion, <i>etc.</i></span>
536 </div>
537 </div>
538 <div class="sws-slide">
539   <h1>Typing of patterns (with accumulators) 1/2</h1>
540   <p>Well known that typing path expressions escapes regular tree languages
541     (i.e. &cduce;'s types). Consider:
542   </p>
543 <pre style="margin:-3em 0pt -1em;">
544       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"/>
545 </pre>
546 <p>The set of all <tt><u>a</u></tt> or <tt><u>b</u></tt> labeled
547   descendants
548   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>
549 which is not a type.</p>
550 <p> Intuitively it means that when applying a
551   recursive pattern against a recursive type, we may generate an
552   <s>infinite number of distinct types</s> for an accumulator.
553 </p>
554 </div>
555 <div class="sws-slide">
556   <h1>Typing of patterns (with accumulators) 2/2</h1>
557   <p>We use the typing relation of operators to introduce
558   approximations:</p>
559   <pre>
560     <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/>
561     <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>
562   </pre>
563   <p>Ensures termination of typechecking of patterns.</p>
564 </div>
565 <div class="sws-slide">
566   <h1>Results</h1>
567 <p>Zippers (in values, types, patterns) are orthogonal to the rest of the language</p>
568 <ul>
569   <li><u>Subtyping and typechecking</u> are extended straightforwardly</li>
570   <li>Typing of patterns introduces <u>sound approximations</u> only for accumulators</li>
571   <li>Provided the operators are sound, the whole language remains <u>type-safe</u></li>
572 </ul>
573 </div>
574 <div class="sws-slide">
575   <h1>From zippers to XPath</h1>
576   <p>We use  <u>regular expressions</u> over basic &left;/&right; zippers to encode XPath</p>
577 <code style="width:50%;float:left;">   <![CDATA[<a>[ <b>[
578           <c>[]
579           <d>[]
580           <e>[ <f> [] ]
581         ]
582    ]]]>
583 </code><img style="width:17.5%;" src="ex_ntree.svg" alt="ex_ntree" /><br/>
584 <p class="sws-pause"><img style="margin-top:-1em;margin-left:5%;width:85%;" src="rb_tree.svg" alt="rb_tree"/></p>
585 </div>
586 <div class="sws-slide">
587 <h1>Downward XPath axes</h1>
588 <pre style="background:white">     <tt>self ::</tt> t ≡    (ẋ <tt>&amp;</tt> t | _ )<sub>&ztop;</sub>                                (Init(ẋ) = [], Op(ẋ) = <tt>snoc</tt>)
589
590      <span class="sws-pause"><tt>child ::</tt> t ≡  <tt>&lt;_&gt;[</tt> (ẋ <tt>&amp;</tt> t | _ )<tt>* ]</tt><sub>&ztop;</sub></span>
591 </pre>
592 <p class="sws-pause">Example: applying <tt><u>child::&lt;b&gt;_</u></tt>   to the document</p>
593 <code>      &lt;doc&gt;[ &lt;a&gt;[]    &lt;b&gt;[]    &lt;c&gt;[]    &lt;b&gt;[] ]<sub>&bcirc;</sub>
594         <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>
595
596         <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>
597 </code>
598
599 <pre class="sws-pause">
600      <tt>descendant-or-self::</tt> t ≡   X ≡ ((ẋ <tt>&amp;</tt> t | _ ) <tt> &amp; &lt;_&gt;[</tt> X <tt>* ]</tt>)<sub>&ztop;</sub>
601
602      <tt>descendant</tt> :: t ≡ <tt>&lt;_&gt;[ (descendant-or-self::</tt>t<tt>)* ]</tt><sub>&ztop;</sub>
603 </pre>
604 <!--
605 <script type="text/javascript">
606 /* <![CDATA[ */
607   var svgDoc = null;
608
609   function reset () {
610         svgDoc = svgDoc || document.getElementById("svgRBTree").contentDocument;
611         var f = svgDoc.getElementById("nodef");
612         f.style['fillOpacity'] = "0";
613         var elems = svgDoc.getElementsByClassName("parentf");
614         for(var i = 0; i < elems.length; i++) {
615             elems[i].style['strokeWidth'] = '2px';
616        };
617   };
618
619   reg (0, function (c) {
620          console.log(0);
621          reset();
622   });
623
624   reg (1, function (c) {
625          console.log(1);
626          var f = svgDoc.getElementById("nodef");
627          console.log(' Opacity ' + f.style['fillOpacity']);
628          f.style['fillOpacity'] = "0.5";
629          console.log(' Opacity ' + f.style['fillOpacity']);
630      });
631
632   reg (2, function (c) {
633          console.log(2);
634         var elems = svgDoc.getElementsByClassName("parentf");
635         for(i = 0; i < elems.length; i++) {
636              elems[i].style['strokeWidth'] = '6px';
637           }
638      });
639    reg (3, function (c) {          console.log(3); reset(); });
640 /*]]>*/
641 </script>
642 -->
643 </div>
644 <div class="sws-slide">
645 <h1>Upward XPath axes</h1>
646 <div style="position:absolute; width:80%; left:10%;top:15%">
647 <object id="svgRBTree" data="rb_tree.svg" type="image/svg+xml" style="z-index:1;position:absolute;width:100%"  />
648 <object class="sws-onframe-1" id="svgRBTree1" data="rb_tree01.svg" type="image/svg+xml" style="z-index:1;position:absolute;width:100%" />
649 <object class="sws-onframe-2" id="svgRBTree2" data="rb_tree02.svg" type="image/svg+xml" style="z-index:3;position:absolute;width:100%"  />
650 <object class="sws-onframe-3" id="svgRBTree3" data="rb_tree03.svg" type="image/svg+xml" style="z-index:4;position:absolute;width:100%"  />
651 <object class="sws-onframe-4" id="svgRBTree4" data="rb_tree04.svg" type="image/svg+xml" style="z-index:5;position:absolute;width:100%"  />
652 </div>
653 <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>
654                                              
655 <span class="sws-onframe-5">     <tt>ancestor ::</tt> t ≡   &top;<sub> ( (&left;_) · (&right;_)* · (&right; ẋ &amp; t) )* · &bcirc; </sub></span>
656
657
658
659
660 </pre>
661 <pre style="position:absolute;bottom:5%;z-index:2;">
662
663                                <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>
664
665                                           <span style="color:#1fb01b;border-color:#1fb01b;border-top-style:dashed;border-top-width:3pt;position:relative;top:0.5em;">         parent         </span>
666
667
668
669 </pre>
670 </div>
671 <div class="sws-slide">
672   <h1>Other results</h1>
673 <ul>
674   <li>Encoding of paths is compositional</li>
675   <li>Once we have path, translation from XQuery to &cduce; is straightforward</li>
676   <li>We also give a direct typing algorithm for XQuery 3.0 rather than typing the translation to &cduce;</li>
677 </ul>
678 </div>
679 <div class="sws-slide">
680 <h1>Conclusion, thoughts and future work</h1>
681 <ul>
682   <li>Adding path expressions to a functional language such as &cduce; is possible </li>
683   <li>Semantic subtyping and regular expression types play nicely with zippers</li>
684   <li>In terms of language design, exposing directly zippers patterns to the programmer is a big no-no</li>
685   <li>Can also be applied to XSLT</li>
686   <li>Implementation on-going (including a &cduce; to javascript backend)</li>
687   <li>Extend the approach to Json (google ``path language for json''), i.e. generalise from products to extensible records</li>
688 </ul>
689
690 </div>
691
692   </body>
693 </html>