Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > a2da5eab8fb68605fe995d94e514eeb0 > files > 34

cduce-0.5.3-2mdv2010.0.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>CDuce: Higher-order functions</title><meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"/><link type="text/css" rel="stylesheet" href="cduce.css"/></head><body style="margin: 0; padding : 0;"><table border="0" width="100&#37;" cellspacing="10" cellpadding="0"><tr><td valign="top" align="left" style="width:20&#37;;"><div class="leftbar" id="leftbar"><div class="smallbox"><ul><li><a href="#intro">Introduction</a></li><li><a href="#comp">A complex example</a></li></ul><p>
You can cut and paste the code on this page and 
test it on the <a href="http://reglisse.ens.fr/cgi-bin/cduce">online interpreter</a>.
</p></div></div></td><td><h1>Higher-order functions</h1><div class="mainpanel"><div class="smallbox"><p><a href="index.html">CDuce: documentation</a>: <a href="tutorial.html">Tutorial</a>: Higher-order functions</p><p><a href="tutorial_queries.html"><img class="icon" width="16" alt="Previous page:" height="16" src="img/left.gif"/> Queries</a> <a href="tutorial_exercises.html"><img class="icon" width="16" alt="Next page:" height="16" src="img/right.gif"/> Exercises</a></p></div><div><h2><a name="intro">Introduction</a></h2><p><b style="color:#FF0080">TO BE DONE</b></p></div><div><h2><a name="comp">A complex example</a></h2><p><b style="color:#FF0080">Rewrite in order not to introduce new type declarations</b></p><div class="code"><pre>
type Program = &lt;program&gt;[ Day* ]
type Day = &lt;date day=String&gt;[ Invited? Talk+ ]
type Invited = &lt;invited&gt;[ Title Author+ ]
type Talk = &lt;talk&gt;[ Title Author+ ]
type Author = &lt;author&gt; String
type Title = &lt;title&gt; String

let patch_program 
  (p :[Program], f :<strong class="highlight">(Invited -&gt; Invited) &amp; (Talk -&gt; Talk)</strong>):[Program] =
  xtransform p with (Invited | Talk) &amp; x -&gt; [ (f x) ]

let first_author (<strong class="highlight">[Program] -&gt; [Program];
                  Invited -&gt; Invited;
                  Talk -&gt; Talk</strong>)
| [ Program ] &amp; p -&gt; patch_program (p,first_author)
| &lt;(k)&gt;[ t a _* ] -&gt; &lt;(k)&gt;[ t a ] 
</pre></div></div><div class="meta"><p><a href="sitemap.html">Site map</a></p></div><div class="smallbox"><p><a href="index.html">CDuce: documentation</a>: <a href="tutorial.html">Tutorial</a>: Higher-order functions</p><p><a href="tutorial_queries.html"><img class="icon" width="16" alt="Previous page:" height="16" src="img/left.gif"/> Queries</a> <a href="tutorial_exercises.html"><img class="icon" width="16" alt="Next page:" height="16" src="img/right.gif"/> Exercises</a></p></div></div></td></tr></table></body></html>