<!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%" cellspacing="10" cellpadding="0"><tr><td valign="top" align="left" style="width:20%;"><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 = <program>[ Day* ] type Day = <date day=String>[ Invited? Talk+ ] type Invited = <invited>[ Title Author+ ] type Talk = <talk>[ Title Author+ ] type Author = <author> String type Title = <title> String let patch_program (p :[Program], f :<strong class="highlight">(Invited -> Invited) & (Talk -> Talk)</strong>):[Program] = xtransform p with (Invited | Talk) & x -> [ (f x) ] let first_author (<strong class="highlight">[Program] -> [Program]; Invited -> Invited; Talk -> Talk</strong>) | [ Program ] & p -> patch_program (p,first_author) | <(k)>[ t a _* ] -> <(k)>[ 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>