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"
5 <!ENTITY in "<small style='font-size:small'>∈</small>">
6 <!ENTITY notin "<small style='font-size:small'>∉</small>">
13 <!ENTITY cduce "ℂDuce">
16 <!ENTITY setminus "∖" >
17 <!ENTITY bottom "<tt>Empty</tt>" > <!-- 𝟘 -->
18 <!ENTITY top "<tt>Any</tt>" > <!-- 𝟙 -->
19 <!ENTITY subseteq "⊆" >
24 <!ENTITY lbrack "<span style='font-size:xx-large;'>⟦</span>" >
25 <!ENTITY rbrack "<span style='font-size:xx-large;'>⟧</span>" >
27 <!ENTITY left "<tt style='color:#d33'>L</tt>" >
28 <!ENTITY right "<tt style='color:#33d'>R</tt>">
30 <!ENTITY rleadsto "⟿"> <!-- -->
37 <html xmlns="http://www.w3.org/1999/xhtml" >
39 <title>A Core Calculus for XQuery 3.0</title>
41 <meta http-equiv="Content-Type"
42 content="text/html; charset=utf-8" />
43 <meta name="copyright"
44 content="Copyright © 2013 Kim Nguyễn" />
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>
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" />
57 <!-- Customize some templates and initialize -->
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;
64 //Ensures that we load SWS at the very end, after MathJax has
67 $(window).load(SWS.Presentation.init);
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);
76 var reg = SWS.Presentation.registerCallback;
82 src: url("OpenSans-Regular.ttf") format("truetype");
83 font-family: "Open Sans";
88 src: url("OpenSans-Bold.ttf") format("truetype");
89 font-family: "Open Sans";
94 src: url("OpenSans-Italic.ttf") format("truetype");
95 font-family: "Open Sans";
100 src: url("OpenSans-BoldItalic.ttf") format("truetype");
101 font-family: "Open Sans";
109 font-family: 'Open Sans',sans-serif;
111 background-color: white;
121 pre, dfn, .infer { font-family : serif;
128 vertical-align:text-bottom;
129 display:inline-block;
140 vertical-align:text-bottom;
141 display:inline-block;
147 margin: 0pt 0pt 0pt 0pt;
148 padding: 0pt 0pt 0pt 0pt;
151 .infer > span:last-child {
152 margin: 0pt 0pt 0pt 0pt;
153 padding: 0pt 0pt 0pt 0pt;
154 border-width: 1pt 0pt 0pt 0pt;
156 border-color: #292928;
159 vertical-align:text-top;
165 margin: 0pt 0pt 0pt 0pt;
166 padding: 0pt 0pt 0pt 0pt;
168 span.fill { display:inline-block;
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">
182 <td>Giuseppe Castagna<sup>1</sup></td>
183 <td>Hyeonseung Im<sup>2</sup></td>
186 <td><u>Kim Nguyễn</u><sup>3</sup></td>
187 <td>Véronique Benzaken<sup>3</sup></td>
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
197 <div class="sws-slide">
198 <h1>The XQuery 3.0 W3C Standard</h1>
199 <code style="background:white;font-size:90%;">
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>)
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 <a href={<u>$l</u><span class="xpath">/@href</span>}><b>{<u>$l</u><span class="xpath">/text()</span>}</b></a>
212 default return <u>$l</u>
214 <span class="ts">default return</span> <u>$link</u>
217 let $bold_links := get_links(document("file.html"), $pretty)
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"));
230 <div class="sws-slide">
235 + nice declarative syntax for paths
238 - weird distinction between types/value case<br/>
239 - <s>no type-checking for functions</s>
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>
247 <div class="sws-slide">
249 <p>A polymorphic functional language equipped with
250 semantic subtyping</p>
252 <code style="font-size:90%"> <i>(* Here _ is an alias for the top type Any *)</i>
254 let <u>pretty</u> (<a>Any <span class="typ">&rarrow;</span> <a>Any <span class="typ">&</span> Any<span class="typ">\</span><a>Any <span class="typ">&rarrow;</span> Any<span class="typ">\</span><a>Any)
256 | <span class="pat"><a class="style1" href=<u>h</u> ..> <u>l</u></span> &rarrow; <a href=<u>h</u>>[ <b><u>l</u> ]
257 | <span class="pat">x</span> &rarrow; x
260 let <u>get_links</u> (page: <(Any)>Any) (print: <a>Any <span class="typ">&rarrow;</span> <a>Any) : <span class="typ">[ <a>Any * ]</span> =
263 <span class="pat"><a>_ & x</span> &rarrow; [ (print x) ]
264 | <span class="pat">< (_\‘b) > l</span> &rarrow;
265 (<span class="lc">transform l with</span> <span class="pat">(i & <_>_)</span> &rarrow; get_links i print)
266 | <span class="pat">_</span> &rarrow; [ ]
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"));
276 <div class="sws-slide">
280 + Statically typed <br/>
281 + compact (and efficient) type and value pattern-matching
284 - <s>complex navigation encoded through recursion</s><br/>
285 - no type inference for functions
288 <p>Writing functions to traverse documents is painfull</p>
290 <div class="sws-slide">
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
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>
301 <li class="ll" style="padding:1em 0em 1em 0em;">Perform a type-directed translation from XQuery to
304 <script type="text/javascript">
305 reg (1, col_change(".lh", "#f83"));
306 reg (1, col_change(".ll", "#bbb"));
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 ∖ t</mark> | <mark>⊤</mark> | <mark>⊥</mark> | α
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>α</dfn> : type variables<br/>
320 types are interpreted co-inductively: recursive types and regular
321 expression types<br/>
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>)
327 <pre style="width:30%;display:inline-block;"> <span class="sws-pause">t<sub>1</sub> ≡ <tt>[ Int* Bool+ ]</tt></span></pre>
330 <div class="sws-slide">
331 <h1>Semantic subtyping</h1>
332 <pre style="text-align:center;">
333 t ≤ s &Lrarrow; [t] ⊆ [s]
335 <p><dfn>[ ]</dfn> interpretation of types as sets of
337 Allows to reason <i>modulo</i> semantic equivalence of type connectives :
340 <tt>[ Int* (Int | Bool*)? ]</tt> &land; <tt>[ Int+ (Bool+ | Int)* ]</tt> ≡ <tt>[Int+ Bool*]</tt>
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) | λx.e
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>)))
351 <p>XML documents are tagged sequences: <pre style="text-align:center;"><tt><foo>[</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>
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>
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 & 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 &</mark><br/>
364 patterns are also co-inductively interpreted (recursive patterns)
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/>
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>
379 [ _* (<u>x</u> & Int) Bool* (<u>y</u> & Bool) ] &rarrow; (<u>x</u>, <u>y</u>)
380 | [ _* (<u>x</u> & Int) ] &rarrow; (<u>x</u>, `false)
381 | [ ] &rarrow; (0, `false)
384 <li><dfn>&lbag;<tt>[ _* (<u>x</u> & Int) Bool* (<u>y</u> & Bool) ]</tt>&rbag; <span style="display:inline-block;width:5em;text-align:center"> ≡</span> <tt>[ ⊤* Int Bool+ ]</tt></dfn><br/>
385 <span style="text-align:right;display:inline-block;width:94%;">{ x ↦ <tt>Int</tt>, y ↦ <tt>Bool</tt> }</span>
387 <li><dfn>&lbag;<tt>[ _* (<u>x</u> & Int) ]</tt>&rbag; <span style="display:inline-block;width:5em;text-align:center"> ≡</span> <tt>[ ⊤* Int ]</tt></dfn><br/>
388 <span style="text-align:right;display:inline-block;width:58%;"> { x ↦ <tt>Int</tt> }</span>
390 <li>Since <dfn><tt>[Int+ Bool* ]</tt> ∖ ( <tt>[ ⊤* Int Bool+ ]</tt> &lor; <tt>[ ⊤* Int]</tt>) ≡ ⊥ </dfn><br/>
391 the third case is unreachable.
399 <div class="sws-slide">
400 <h1>Zippers (1/2)</h1>
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>
409 <pre style="text-align:center;"> v ::= … | v<sub>δ</sub>
410 δ ::= &bcirc; | &left;v · δ | &right;v · δ
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>
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>
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>τ</sub>
431 τ ::= &bcirc; | &left;t · τ | &right;t · τ | τ &lor; τ | τ ∖ τ | &ztop;
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;⊤)* &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>
443 <div class="sws-slide">
444 <h1>Tree navigation</h1>
445 <p>Since patterns contain types, we can check complex
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><a>_</tt>:</span>
449 p ≡ <tt id="test"><a>_</tt> &lor; <tt><_>[ _* <dfn>p</dfn> _* ]</tt>
451 <span style="font-family:'Open Sans';">Deos not have an ancestor <tt><b>_</tt>:</span>
452 τ ≡ &bcirc; &lor; &right;(⊤∖ <tt><b>_</tt>) · τ &lor; &left;(⊤∖ <tt><b>_</tt>) · τ </pre>
453 <code style="width:20%;display:inline-block;vertical-align:middle">
455 <dfn>p<sub>τ</sub></dfn> & <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
460 Remark: (recursive) patterns <u>already perform a recursive traversal
463 <em>Idea</em>: Piggy back on the traversal and <em>accumulate</em>
464 nodes in special variables
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/>
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> ∈ &mathV;</dfn> : an initial value<br/>
484 <div class="sws-slide">
485 <h1>Some operators</h1>
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/>
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>
495 <div class="sws-slide">
496 <h1>Pattern matching semantics (simplified)</h1>
497 <pre style="text-align:center;">
498 σ ⊢ v / p &rleadsto; γ, σ'
500 <p style="font-size:90%"><dfn><u>σ</u>, <u>σ'</u></dfn>: mapping from accumulators to
502 <dfn><u>v</u></dfn>: input value<br/>
503 <dfn><u>p</u></dfn>: pattern<br/>
504 <dfn><u>γ</u></dfn>: mapping from capture variables to
507 <div style="padding:0em 1em 0em; text-align:justify;background:white;">
509 <span> v ∈ [ t ]</span>
510 <span>σ; δ ⊢ v / t &rleadsto; ∅,
512 </div><span>(type)</span>
516 <span>σ ⊢ v / ẋ &rleadsto; ∅,
517 σ[ ẋ := Op(ẋ) (v, σ(ẋ)) ]</span>
518 </div><span>(acc)</span>
522 <span>σ ⊢ v / x &rleadsto; { x ↦ v },
524 </div><span>(var)</span>
527 <span>σ ⊢ (fst v)/p<sub>1</sub>
528 &rleadsto; γ<sub>1</sub>, σ' </span>
529 <span>σ' ⊢ (snd v)/p<sub>2</sub>
530 &rleadsto; γ<sub>2</sub>, σ''
532 <span>σ ⊢ v /
533 (p<sub>1</sub>, p<sub>2</sub>) &rleadsto;
534 γ<sub>1</sub>∪ γ<sub>2</sub>,
536 </div><span>(pair)</span> <span class="fill"></span>
537 <span style="position:relative;top:-1em;">Remember, if <dfn>v ≡ (v1,v2)<sub>δ</sub></dfn> then <dfn><tt>fst v</tt> ≡ v<sub>1 &left;v · δ</sub></dfn> and <dfn><tt>snd v</tt> ≡ v<sub>2 &right;v · δ</sub></dfn><br/>
538 (some other rules for alternation, failure, recursion, <i>etc.</i>)</span>
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:
546 <pre style="margin:-3em 0pt -1em;">
547 t ≡ <tt><c>[ <u><a>[]</u> t <u><b>[]</u> ] </tt> &lor; <tt><c>[]</tt> <img style="margin-left:3em;width:15%;vertical-align:middle;" src="anbn_tree.svg" alt="anbn"/>
549 <p>The set of all <tt><u>a</u></tt> or <tt><u>b</u></tt> labeled
551 is <dfn>{ <tt>[<u><a>[]</u></tt><sup>n</sup> <tt><u><b>[]</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.
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
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>
566 <p>Ensures termination of typechecking of patterns.</p>
568 <div class="sws-slide">
570 <p>Zippers (in values, types, patterns) are a conservative extension</p>
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>
577 <div class="sws-slide">
578 <h1>Downward XPath axes</h1>
579 <pre style="background:white"> <tt>self ::</tt> t ≡ (ẋ <tt>&</tt> t | _ )<sub>&ztop;</sub> (Init(ẋ) = [], Op(ẋ) = <tt>snoc</tt>)
581 <span class="sws-pause"><tt>child ::</tt> t ≡ <tt><_>[</tt> (ẋ <tt>&</tt> t | _ )<tt>* ]</tt><sub>&ztop;</sub></span>
583 <p class="sws-pause">Example: applying <tt><u>child::<b>_</u></tt> to the document</p>
584 <code> <doc>[ <a>[] <b>[] <c>[] <b>[] ]<sub>&bcirc;</sub>
585 <span class="sws-pause"><_>[ <span class="sws-pause"> _</span> <mark class="sws-pause">(ẋ & <b>_)</mark> <span>_</span> <mark>(ẋ & <b>_)</mark>]<sub >&ztop;</sub></span>
587 <span class="sws-pause"> ẋ↦ [ <b>[]<sub>&left;… &right;… &right;… &bcirc;</sub> <b>[]<sub>&left;… &right;… &right;… &right;… &right;… &bcirc;</sub> ] </span>
590 <pre class="sws-pause">
591 <tt>descendant-or-self::</tt> t ≡ X ≡ ((ẋ <tt>&</tt> t | _ ) <tt> & </tt> (<tt><_>[</tt> X <tt>* ]</tt>)<sub>&ztop;</sub> | _ )
593 <tt>descendant</tt> :: t ≡ <tt><_>[ (descendant-or-self::</tt>t<tt>)* ]</tt><sub>&ztop;</sub>
596 <script type="text/javascript">
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';
610 reg (0, function (c) {
615 reg (1, function (c) {
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']);
623 reg (2, function (c) {
625 var elems = svgDoc.getElementsByClassName("parentf");
626 for(i = 0; i < elems.length; i++) {
627 elems[i].style['strokeWidth'] = '6px';
630 reg (3, function (c) { console.log(3); reset(); });
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>[
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>
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%" />
657 <pre style="position:absolute;bottom:5%;z-index:1;"> <tt>parent ::</tt> t ≡ ⊤<sub> (&left;_) · (&right;_)* · (&right; ẋ & t) · (( (&left; _) · &ztop;) &lor; &bcirc; )</sub>
659 <span class="sws-onframe-5"> <tt>ancestor ::</tt> t ≡ ⊤<sub> ( (&left;_) · (&right;_)* · (&right; ẋ & t) )* · &bcirc; </sub></span>
665 <pre style="position:absolute;bottom:5%;z-index:2;">
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>
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>
675 <div class="sws-slide">
676 <h1>Other results</h1>
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>
683 <div class="sws-slide">
684 <h1>Conclusion, thoughts and future work</h1>
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>
692 <p class="sws-pause" style="text-align:center;"><b><u>Thank you!</u></b></p>