<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:planet="http://planet.intertwingly.net/" xmlns:indexing="urn:atom-extension:indexing" indexing:index="no"><access:restriction xmlns:access="http://www.bloglines.com/about/specs/fac-1.0" relationship="deny"/>
  <title>OCamlcore Planet</title>
  <updated>2010-03-11T03:00:29Z</updated>
  <generator uri="http://intertwingly.net/code/venus/">Venus</generator>
  <author>
    <name>OCamlcore Admins</name>
    <email>planet@ocamlcore.org</email>
  </author>
  <id>http://planet.ocamlcore.org/atom.xml</id>
  <link href="http://planet.ocamlcore.org/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://planet.ocamlcore.org" rel="alternate"/>

  <entry xml:lang="en">
    <id>tag:le-gall.net,2010-03-10:/sylvain+violaine/blog/55</id>
    <link href="http://le-gall.net/sylvain+violaine/blog/index.php?2010/03/10/55-llvm-ocaml-and-debian" rel="alternate" type="text/html"/>
    <title xml:lang="en">LLVM, OCaml and Debian</title>
    <summary xml:lang="en">I hope some people from the OCaml community will enjoy this changelog, extracted from llvm 2.6-7, which has just been uploaded:


  [ Arthur Loiret ]
   
  [...]

  [ Sylvain Le Gall ]
  * Build a libllvm-ocaml-dev package, which contains the OCaml binding:
    Closes: #568556.
    -...</summary>
    <content type="xhtml" xml:lang="en"><div xmlns="http://www.w3.org/1999/xhtml"><p>I hope some people from the OCaml community will enjoy this changelog, extracted from llvm 2.6-7, which has just been uploaded:</p>

<pre>  [ Arthur Loiret ]
   
  [...]

  [ Sylvain Le Gall ]
  * Build a libllvm-ocaml-dev package, which contains the OCaml binding:
    Closes: #568556.
    - debian/debhelper.in/libllvm-ocaml-dev.{dirs,doc-base,install,META}: Add.
    - debian/control.in/source: Build-Depends on ocaml-nox (&gt;= 3.11.2),
      ocaml-best-compilers | ocaml-nox, dh-ocaml (&gt;= 0.9.1).
    - debian/packages.d/llvm.mk:
      + (llvm_packages): Add libllvm-ocaml-dev.
      + (libllvm-ocaml-dev_extra_binary): Define, install META file.
    - debian/rules.d/binary.mk: Add dh_installdirs and dh_ocaml.
    - debian/rules.d/vars.mk:
      + include /usr/share/ocaml/ocamlvars.mk.
      + Configure with --with-ocaml-libdir=$(OCAML_STDLIB_DIR)/llvm.
  * debian/rules.d/build.mk: Fix symlinks pointing to the $DESTDIR.</pre>


<p>In other words: LLVM is now built with its OCaml bindings and a META file for findlib. It will take some days before reaching every architectures, but hopefully it will be in Squeeze (next Debian stable release).</p>


<p>Thanks to Arthur Loiret for the quick upload.</p></div>
    </content>
    <updated>2010-03-10T18:07:37Z</updated>
    <category label="Debian" term="Debian"/>
    <author>
      <name>gildor</name>
    </author>
    <source>
      <id>tag:le-gall.net,2010:/sylvain+violaine/blog/index.php</id>
      <link href="http://le-gall.net/sylvain+violaine/blog/index.php" rel="alternate" type="text/html"/>
      <link href="http://le-gall.net/sylvain+violaine/blog/atom.php" rel="self" type="application/atom+xml"/>
      <subtitle xml:lang="en">Debian and OCaml news</subtitle>
      <title xml:lang="en">Blog of Sylvain Le Gall</title>
      <updated>2010-03-10T18:07:37Z</updated>
    </source>
  </entry>

  <entry>
    <id>http://forge.ocamlcore.org/forum/forum.php?forum_id=559</id>
    <link href="http://forge.ocamlcore.org/forum/forum.php?forum_id=559" rel="alternate" type="text/html"/>
    <title>OCaml Meeting 2010 poll results</title>
    <summary>I know it is a bit late, but I would like to give the results of the poll for OCaml Meeting 2010. I use a weighted mean of the poll answers to sort the results. Values of the answers range from 5 to 1, weight is the matching percentage of votes.

The date was chosen according to your answers, since Friday 16th April came first with a mean value of 3.85. Saturday 17th was second with 3.40.

For the last hour, the demonstration time came first with 3.84, then discussion time (3.78) and lightning talks (3.62).

There were 32 people that answered the poll. 

I thank all the OCaml community to help us choose the right options. 

See you at OCaml Meeting 2010
http://wiki.cocan.org/events/europe/ocamlmeetingparis2010</summary>
    <updated>2010-03-10T09:53:36Z</updated>
    <category term="OCaml Meeting"/>
    <author>
      <name>Sylvain Le Gall</name>
    </author>
    <source>
      <id>http://forge.ocamlcore.org</id>
      <link href="http://forge.ocamlcore.org" rel="alternate" type="text/html"/>
      <link href="http://forge.ocamlcore.org/export/rss_sfnews.php" rel="self" type="application/rdf+xml"/>
      <rights>Copyright 1999-2000 VA Linux Systems, Inc.</rights>
      <subtitle>OCamlForge Project News Highlights</subtitle>
      <title>OCamlForge Project News</title>
      <updated>2010-03-11T03:00:26Z</updated>
    </source>
  </entry>

  <entry>
    <id>http://forge.ocamlcore.org/forum/forum.php?forum_id=558</id>
    <link href="http://forge.ocamlcore.org/forum/forum.php?forum_id=558" rel="alternate" type="text/html"/>
    <title>OCaml Meeting 2010, 3 weeks before end of subscription</title>
    <summary>For the third time, I am proud to invite all OCaml enthusiasts to join us at OCaml Meeting 2010 in Paris.

This year event takes place in Paris on Friday 16th April 2010. Subscription is opened and will be closed on Friday 2nd April 2010.

Presentations include:

    * Enforcing Type-Safe Linking using Inter-Package Relationships for OCaml Debian packages
    * The Ocamlviz visualization toolkit
    * Cluster computing in Ocaml
    * Ocaml in a web startup
    * React, functional reactive programming for OCaml
    * OASIS, a Cabal like system for OCaml
    * OPA, same web, but with types and lambda
    * OC4MC, Objective Caml for MultiCore
    * Lwt, Cooperative Light-Weight Threads
    * naclgrid: the collaborative rendering farm, a JoCaml-powered desktop grid

The meeting is sponsored by INRIA, the Caml Consortium and OCamlCore. Inscription is free but the number of participants is limited.

Further information and inscriptions:
http://wiki.cocan.org/events/europe/ocamlmeetingparis2010

The day after OCaml Meeting, Mehdi Dogguy from PPS helps me to organize an informal day where OCaml teams can meet to work. We will have 2 classrooms, each can host 45 persons. There will be an internet access and a blackboard in each room. Inscription is free.

Further information and inscriptions:
http://wiki.cocan.org/events/europe/ocamlhackingday2010

Volunteers willing to help before/during these events can contact me directly. We are particularly looking for a video team. You can also forward this invitation to any groups that can be interested in (Haskell user group, CUFP mailing list...)

For people who need further information, you can contact me (see wiki.cocan.org for contact details).

Sylvain Le Gall on behalf of the OCaml Meeting organization team.</summary>
    <updated>2010-03-10T09:53:30Z</updated>
    <category term="OCaml Meeting"/>
    <author>
      <name>Sylvain Le Gall</name>
    </author>
    <source>
      <id>http://forge.ocamlcore.org</id>
      <link href="http://forge.ocamlcore.org" rel="alternate" type="text/html"/>
      <link href="http://forge.ocamlcore.org/export/rss_sfnews.php" rel="self" type="application/rdf+xml"/>
      <rights>Copyright 1999-2000 VA Linux Systems, Inc.</rights>
      <subtitle>OCamlForge Project News Highlights</subtitle>
      <title>OCamlForge Project News</title>
      <updated>2010-03-11T03:00:26Z</updated>
    </source>
  </entry>

  <entry>
    <id>http://alan.petitepomme.net/cwn/2010.03.09.html</id>
    <link href="http://alan.petitepomme.net/cwn/2010.03.09.html" rel="alternate" type="text/html"/>
    <title>Caml Weekly News, 09 Mar 2010</title>
    <summary>gc overhead / MetaOCaml lives! / Encoding an extensible parse tree and subtyping within OCaml / NaCl/OCaml (OCaml as a client-side web programming language) / Commercial Users of Functional Programming - call for participation / Other Caml News</summary>
    <updated>2010-03-09T12:00:00Z</updated>
    <source>
      <id>http://alan.petitepomme.net/cwn/</id>
      <author>
        <name>Caml Weekly News</name>
      </author>
      <link href="http://alan.petitepomme.net/cwn/" rel="alternate" type="text/html"/>
      <link href="http://alan.petitepomme.net/cwn/cwn.rss" rel="self" type="application/rss+xml"/>
      <subtitle>News frow the Caml list</subtitle>
      <title>Caml Weekly News</title>
      <updated>2010-03-09T09:00:08Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://blog.rastageeks.org/spip.php?article58</id>
    <link href="http://blog.rastageeks.org/spip.php?article58" rel="alternate" type="text/html"/>
    <title xml:lang="en">Liquidsoap-full 0.9.2-2 and ocaml-cry 0.1.2</title>
    <content type="xhtml" xml:lang="en"><div xmlns="http://www.w3.org/1999/xhtml"><div class="rss_texte"><p>An issue with the new ocaml-cry module that replaces the shout library has been recently discovered.</p> <p>This issue was related to the data sent to the icecast server and could result in a higher load and loss of data when sending data to the server.</p> <p>We have released a new version of ocaml-cry that fixes this issue, numbered 0.1.2.</p> <p>We have also released a new liquidsoap-full tarball, numbered 0.9.2-2 and now available in the download section on <a class="spip_out" href="http://sourceforge.net/projects/savonet/files/">sourceforge.net</a>.</p> <p>Additionally, our custom stable packages have been rebuild against this new version, both for the i386 and the amd64 architecture.</p> <p>The package available in Debian sid/unstable is now built against the fixed ocaml-cry as well.</p> <p>We recommend that any user that uses liquidsoap 0.9.2 updates its liquidsoap to make sure it uses ocaml-cry 0.1.2.</p> <p>Please note that ocaml modules are not dynamically loaded, so you need to rebuild liquidsoap against the new ocaml-cry if you are building from source.</p></div></div>
    </content>
    <updated>2010-03-08T23:13:43Z</updated>
    <category term="debian"/>
    <category term="ocaml"/>
    <author>
      <name>Toots</name>
    </author>
    <source>
      <id>http://blog.rastageeks.org/</id>
      <logo>http://blog.rastageeks.org/local/cache-vignettes/L100xH99/siteon0-cb303.png</logo>
      <link href="http://blog.rastageeks.org/" rel="alternate" type="text/html"/>
      <link href="http://blog.rastageeks.org/spip.php?page=rss&amp;id_mot=2" rel="self" type="application/rss+xml"/>
      <title xml:lang="en">blog.rastageeks.org</title>
      <updated>2010-03-11T03:00:05Z</updated>
    </source>
  </entry>

  <entry xml:lang="en">
    <id>http://caml.inria.fr/cgi-bin/hump.cgi?contrib=447</id>
    <link href="http://caml.inria.fr/cgi-bin/hump.cgi?contrib=447" rel="alternate" type="text/html"/>
    <title>OCaml CSV 1.2</title>
    <summary>This library can read and write CSV files, including all extensions used by Excel - eg. quotes, newlines, 8 bit characters in fields, "0 etc.

The library comes with a handy command line tool called csvtool for handling CSV files from shell scripts.</summary>
    <updated>2010-03-08T10:18:55Z</updated>
    <source>
      <id>http://caml.inria.fr/cgi-bin/hump.cgi</id>
      <logo>http://caml.inria.fr//pub/logos/caml-inria-fr.128x58.gif</logo>
      <author>
        <name>The Caml Humps</name>
        <email>hump@caml.inria.fr</email>
      </author>
      <link href="http://caml.inria.fr/cgi-bin/hump.cgi" rel="alternate" type="text/html"/>
      <link href="http://caml.inria.fr/hump.rss" rel="self" type="application/rss+xml"/>
      <subtitle>Releases/updates in the Humps</subtitle>
      <title>The Caml Humps</title>
      <updated>2010-03-10T05:50:01Z</updated>
    </source>
  </entry>

  <entry>
    <id>http://upsilon.cc/~zack/blog/posts/2010/03/ocaml_batteries_included_1.1.0_is_in_debian_now/</id>
    <link href="http://upsilon.cc/~zack/blog/posts/2010/03/ocaml_batteries_included_1.1.0_is_in_debian_now/" rel="alternate" type="text/html"/>
    <title>ocaml batteries included 1.1.0 is in debian now</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><h1>OCaml Batteries Included 1.1.0 has arrived in Debian</h1>
<p>I've just uploaded the <strong>Debian package of <a href="https://forge.ocamlcore.org/forum/forum.php?forum_id=552">OCaml
Batteries Included 1.1.0</a></strong> to the Debian unstable
archive; hopefully, it will quickly enter testing to be released
with the next Debian stable release. This is the first release in
Debian of the "new generation" of Batteries Included, which has
followed a strict diet, and now has <a href="http://camomile.sourceforge.net/">Camomile</a> as its only
external dependency.</p>
<p>It took me a while to package it due to an intertwining
transition to OCaml 3.11.2 (during which we have fleshed out the
last remaining few bits of transition to <a href="http://upsilon.cc/~zack/tags/ocaml/../../blog/posts/2009/11/Enforcing_type-safe_linking_using_package_dependencies/">
our new dependency system</a>). Also, I had to fix some typical
build issue with upstream, which kindly coordinated with me to have
the fixes included in 1.1.0.</p>
<p>So go, enjoy Batteries 1.1.0, and let me know your feedback:</p>
<pre><code>    # apt-get install ocaml-batteries-included
</code>
</pre>
<p><small>(check that it will install 1.1.0 though, it might take a
few days to hit your favorite architecture and mirror)</small></p>
<p><strong>Tip:</strong> starting from this version you will need
the following to use Batteries in place of the legacy standard
library in your sources:</p>
<pre><code>    open Batteries_uni
</code>
</pre>
<p>for multi-threaded programs you should rather use <code>open
Batteries</code>. Check the <code>FAQ</code> file installed under
<code>/usr/share/doc/libbatteries-ocaml-dev/</code> for more quick
start information.</p></div>
    </summary>
    <updated>2010-03-06T15:39:15Z</updated>
    <category term="batteries"/>
    <category term="debian"/>
    <category term="lang/english"/>
    <category term="ocaml"/>
    <category term="planet-debian"/>
    <source>
      <id>http://upsilon.cc/~zack/tags/ocaml/</id>
      <author>
        <name>Stefano Zacchiroli</name>
      </author>
      <link href="http://upsilon.cc/~zack/tags/ocaml/" rel="alternate" type="text/html"/>
      <link href="http://upsilon.cc/~zack/tags/ocaml/index.rss" rel="self" type="application/rss+xml"/>
      <subtitle>zack's home page</subtitle>
      <title>tags/ocaml</title>
      <updated>2010-03-06T16:00:08Z</updated>
    </source>
  </entry>

  <entry>
    <id>tag:blogger.com,1999:blog-1445545651031573301.post-122123601620369639</id>
    <link href="http://ambassadortothecomputers.blogspot.com/2010/03/reading-camlp4-part-5-filters.html" rel="alternate" type="text/html"/>
    <title>Reading Camlp4, part 5: filters</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Hey, long time no see!</p> 
<p>It is high time to get back to Camlp4, so I would like to pick up the thread by covering Camlp4 <em>filters</em>. We have previously considered the parsing and pretty-printing facilities of Camlp4 separately. But of course the most common way to use Camlp4 is as a front-end to <code>ocamlc</code>, where it processes files by parsing them into an AST and pretty-printing them back to text (well, not quite—we will see below how the AST is passed to <code>ocamlc</code>). In between we can insert filters to transform the AST.</p> 
<b>A simple filter</b> 
<p>So let’s dive into an example: a filter for type definitions that generates <code>t_to_string</code> and <code>t_of_string</code> functions for a type <code>t</code>, a little like Haskell’s <code>deriving Show, Read</code>. To keep it simple we handle only variant types, and only those where all the arms have no data. Here goes:</p> 
<div class="highlight"><pre><code class="ocaml"><span class="k">module</span> <span class="nc">Make</span> <span class="o">(</span><span class="nc">AstFilters</span> <span class="o">:</span> <span class="nn">Camlp4</span><span class="p">.</span><span class="nn">Sig</span><span class="p">.</span><span class="nc">AstFilters</span><span class="o">)</span> <span class="o">=</span> 
<span class="k">struct</span> 
  <span class="k">open</span> <span class="nc">AstFilters</span> 
</code></pre> 
</div> 
<p>In order to hook into Camlp4’s plugin mechanism we define the filter as a functor. By opening <code>AstFilters</code> we get an <code>Ast</code> module in scope. Unfortunately this is not the same <code>Ast</code> we got previously from <code>Camlp4.PreCast</code> (although it has the same signature) so all our code that uses <code>Ast</code> (including all OCaml syntax quotations) needs to go inside the functor body.</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="k">let</span> <span class="k">rec</span> <span class="n">filter</span> <span class="n">si</span> <span class="o">=</span> 
    <span class="k">match</span> <span class="n">wrap_str_item</span> <span class="n">si</span> <span class="k">with</span> 
      <span class="o">|</span> <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> <span class="k">type</span> <span class="o">$</span><span class="n">lid</span><span class="o">:</span><span class="n">tid</span><span class="o">$</span> <span class="o">=</span> <span class="o">$</span><span class="nn">Ast</span><span class="p">.</span><span class="nc">TySum</span> <span class="o">(_,</span> <span class="n">ors</span><span class="o">)$</span> <span class="o">&gt;&gt;</span> <span class="o">-&gt;</span> 
          <span class="k">begin</span> 
            <span class="k">try</span> 
              <span class="k">let</span> <span class="n">cons</span> <span class="o">=</span> 
                <span class="nn">List</span><span class="p">.</span><span class="n">map</span> 
                  <span class="o">(</span><span class="k">function</span> 
                     <span class="o">|</span> <span class="o">&lt;:</span><span class="n">ctyp</span><span class="o">&lt;</span> <span class="o">$</span><span class="n">uid</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">&gt;&gt;</span> <span class="o">-&gt;</span> <span class="n">c</span> 
                     <span class="o">|</span> <span class="o">_</span> <span class="o">-&gt;</span> <span class="k">raise</span> <span class="nc">Exit</span><span class="o">)</span> 
                  <span class="o">(</span><span class="nn">Ast</span><span class="p">.</span><span class="n">list_of_ctyp</span> <span class="n">ors</span> <span class="bp">[]</span><span class="o">)</span> <span class="k">in</span> 
              <span class="n">to_of_string</span> <span class="n">si</span> <span class="n">tid</span> <span class="n">cons</span> 
            <span class="k">with</span> <span class="nc">Exit</span> <span class="o">-&gt;</span> <span class="n">si</span> 
          <span class="k">end</span> 
       <span class="o">|</span> <span class="o">_</span> <span class="o">-&gt;</span> <span class="n">si</span> 
</code></pre> 
</div> 
<p>The <code>filter</code> function filters <code>Ast.str_item</code>s. (It is not actually recursive but we say <code>let rec</code> so we can define helper functions afterward). If a <code>str_item</code> has the right form we transform it by calling <code>to_of_string</code>, otherwise we return it unchanged. We match a sum type definition, then extract the constructor names (provided that they have no data) into a string list. (Recall that a <code>TySum</code> contains arms separated by <code>TyOr</code>; the call to <code>list_of_ctyp</code> converts that to a list of arms.)</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="ow">and</span> <span class="n">wrap_str_item</span> <span class="n">si</span> <span class="o">=</span> 
    <span class="k">let</span> <span class="o">_</span><span class="n">loc</span> <span class="o">=</span> <span class="nn">Ast</span><span class="p">.</span><span class="n">loc_of_str_item</span> <span class="n">si</span> <span class="k">in</span> 
    <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> <span class="o">$</span><span class="n">si</span><span class="o">$</span> <span class="o">&gt;&gt;</span> 
</code></pre> 
</div> 
<p>For some reason, <code>&lt;:str_item&lt; $si$ &gt;&gt;</code> wraps an extra <code>StSem</code> / <code>StNil</code> around <code>si</code>, so in order to use the quotation syntax on the left-hand side of a pattern match we need to do the same wrapping.</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="ow">and</span> <span class="n">to_of_string</span> <span class="n">si</span> <span class="n">tid</span> <span class="n">cons</span> <span class="o">=</span> 
    <span class="k">let</span> <span class="o">_</span><span class="n">loc</span> <span class="o">=</span> <span class="nn">Ast</span><span class="p">.</span><span class="n">loc_of_str_item</span> <span class="n">si</span> <span class="k">in</span> 
    <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> 
      <span class="o">$</span><span class="n">si</span><span class="o">$;;</span> 
      <span class="o">$</span><span class="n">to_string</span> <span class="o">_</span><span class="n">loc</span> <span class="n">tid</span> <span class="n">cons</span><span class="o">$;;</span> 
      <span class="o">$</span><span class="n">of_string</span> <span class="o">_</span><span class="n">loc</span> <span class="n">tid</span> <span class="n">cons</span><span class="o">$;;</span> 
    <span class="o">&gt;&gt;</span> 
</code></pre> 
</div> 
<p>This <code>str_item</code> replaces the original one in the output, so we include the original one in additional to new ones containing the <code>t_to_string</code> and <code>t_of_string</code> functions.</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="ow">and</span> <span class="n">to_string</span> <span class="o">_</span><span class="n">loc</span> <span class="n">tid</span> <span class="n">cons</span> <span class="o">=</span> 
    <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> 
      <span class="k">let</span> <span class="o">$</span><span class="n">lid</span><span class="o">:</span> <span class="n">tid</span> <span class="o">^</span> <span class="s2">"_to_string"</span><span class="o">$</span> <span class="o">=</span> <span class="k">function</span> 
        <span class="o">$</span><span class="kt">list</span><span class="o">:</span> 
          <span class="nn">List</span><span class="p">.</span><span class="n">map</span> 
            <span class="o">(</span><span class="k">fun</span> <span class="n">c</span> <span class="o">-&gt;</span> <span class="o">&lt;:</span><span class="n">match_case</span><span class="o">&lt;</span> <span class="o">$</span><span class="n">uid</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">-&gt;</span> <span class="o">$`</span><span class="n">str</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">&gt;&gt;)</span> 
            <span class="n">cons</span><span class="o">$</span> 
    <span class="o">&gt;&gt;</span> 
</code></pre> 
</div> 
<p>To convert a variant to a string, we match over its constructors and return the corresponding string.</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="ow">and</span> <span class="n">of_string</span> <span class="o">_</span><span class="n">loc</span> <span class="n">tid</span> <span class="n">cons</span> <span class="o">=</span> 
    <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> 
      <span class="k">let</span> <span class="o">$</span><span class="n">lid</span><span class="o">:</span> <span class="n">tid</span> <span class="o">^</span> <span class="s2">"_of_string"</span><span class="o">$</span> <span class="o">=</span> <span class="k">function</span> 
        <span class="o">$</span><span class="kt">list</span><span class="o">:</span> 
          <span class="nn">List</span><span class="p">.</span><span class="n">map</span> 
            <span class="o">(</span><span class="k">fun</span> <span class="n">c</span> <span class="o">-&gt;</span> <span class="o">&lt;:</span><span class="n">match_case</span><span class="o">&lt;</span> 
       <span class="o">$</span><span class="n">tup</span><span class="o">:</span> <span class="o">&lt;:</span><span class="n">patt</span><span class="o">&lt;</span> <span class="o">$`</span><span class="n">str</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">&gt;&gt;$</span> <span class="o">-&gt;</span> <span class="o">$</span><span class="n">uid</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> 
     <span class="o">&gt;&gt;)</span> 
            <span class="n">cons</span><span class="o">$</span> 
        <span class="o">|</span> <span class="o">_</span> <span class="o">-&gt;</span> <span class="n">invalid_arg</span> <span class="s2">"bad string"</span> 
    <span class="o">&gt;&gt;</span> 
</code></pre> 
</div> 
<p>To convert a string to a variant, we match over the corresponding string for each constructor and return the constructor; we also need a catchall for strings that match no constructor. (What is this <code>tup</code> and <code>patt</code> business? A contrived bug which we will fix below.)</p> 
<div class="highlight"><pre><code class="ocaml">  <span class="o">;;</span> 
  <span class="nn">AstFilters</span><span class="p">.</span><span class="n">register_str_item_filter</span> <span class="k">begin</span> <span class="k">fun</span> <span class="n">si</span> <span class="o">-&gt;</span> 
    <span class="k">let</span> <span class="o">_</span><span class="n">loc</span> <span class="o">=</span> <span class="nn">Ast</span><span class="p">.</span><span class="n">loc_of_str_item</span> <span class="n">si</span> <span class="k">in</span> 
    <span class="o">&lt;:</span><span class="n">str_item</span><span class="o">&lt;</span> 
      <span class="o">$</span><span class="kt">list</span><span class="o">:</span> <span class="nn">List</span><span class="p">.</span><span class="n">map</span> <span class="n">filter</span> <span class="o">(</span><span class="nn">Ast</span><span class="p">.</span><span class="n">list_of_str_item</span> <span class="n">si</span> <span class="bp">[]</span><span class="o">)$</span> 
    <span class="o">&gt;&gt;</span> 
  <span class="k">end</span> 
</code></pre> 
</div> 
<p>Now we register our filter function with Camlp4. The input <code>str_item</code> may contain many <code>str_items</code>s separated by <code>StSem</code>, so we call <code>list_of_str_item</code> to get a list of individuals.</p> 
<div class="highlight"><pre><code class="ocaml"><span class="k">end</span> 
<span class="k">module</span> <span class="nc">Id</span> <span class="o">=</span> 
<span class="k">struct</span> 
  <span class="k">let</span> <span class="n">name</span> <span class="o">=</span> <span class="s2">"to_of_string"</span> 
  <span class="k">let</span> <span class="n">version</span> <span class="o">=</span> <span class="s2">"0.1"</span> 
<span class="k">end</span> 
<span class="o">;;</span> 
<span class="k">let</span> <span class="k">module</span> <span class="nc">M</span> <span class="o">=</span> <span class="nn">Camlp4</span><span class="p">.</span><span class="nn">Register</span><span class="p">.</span><span class="nc">AstFilter</span><span class="o">(</span><span class="nc">Id</span><span class="o">)(</span><span class="nc">Make</span><span class="o">)</span> <span class="k">in</span> <span class="bp">()</span> 
</code></pre> 
</div> 
<p>Finally we register the plugin with Camlp4. The functor application is just for its side effect, so the plugin is registered when its <code>.cmo</code> is loaded. We can compile the plugin with</p> 
<div class="highlight"><pre><code class="bash">ocamlfind ocamlc -package camlp4.quotations.o -syntax camlp4o <span class="se">\</span> 
  -c to_of_string.ml
</code></pre> 
</div> 
<p>and run it on a file (containing <code>type t = Foo | Bar | Baz</code> or something) with</p> 
<div class="highlight"><pre><code class="bash">camlp4o to_of_string.cmo <span class="nb">test</span>.ml
</code></pre> 
</div><b>Ocamlc's AST</b> 
<p>Looks pretty good, right? But something goes wrong when we try to use our plugin as a frontend for <code>ocamlc</code>:</p> 
<div class="highlight"><pre><code class="bash">ocamlc -pp <span class="s1">'camlp4o ./to_of_string.cmo'</span> <span class="nb">test</span>.ml
</code></pre> 
</div> 
<p>We get a preprocessor error, “singleton tuple pattern”. It turns out that Camlp4 passes the processed AST to <code>ocamlc</code> not by pretty-printing it to text, but by converting it to the AST type that <code>ocamlc</code> uses and marshalling it. This saves the time of reparsing it, and also passes along correct file locations (compare to <code>cpp</code>’s <code>#line</code> directives). However, as we have seen, the Camlp4 AST is pretty loose. When converting to an <code>ocamlc</code> AST, Camlp4 does some validity checks on the tree. What can be confusing is that an AST that fails these checks may look fine when pretty-printed.</p> 
<p>Here the culprit is the line</p> 
<div class="highlight"><pre><code class="ocaml">       <span class="o">$</span><span class="n">tup</span><span class="o">:</span> <span class="o">&lt;:</span><span class="n">patt</span><span class="o">&lt;</span> <span class="o">$`</span><span class="n">str</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">&gt;&gt;$</span> <span class="o">-&gt;</span> <span class="o">$</span><span class="n">uid</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> 
</code></pre> 
</div> 
<p>which produces an invalid pattern consisting of a one-item tuple. When pretty-printed, though, the <code>tup</code> just turns into an extra set of parentheses, which <code>ocamlc</code> doesn’t mind. What we wanted was</p> 
<div class="highlight"><pre><code class="ocaml">       <span class="o">$`</span><span class="n">str</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> <span class="o">-&gt;</span> <span class="o">$</span><span class="n">uid</span><span class="o">:</span> <span class="n">c</span><span class="o">$</span> 
</code></pre> 
</div> 
<p>This is a contrived example, but this kind of error is easy to make, and can be hard to debug, because looking at the pretty-printed output doesn’t tell you what’s wrong. One tactic is to run your code in the toplevel, which will print the constructors of the AST as usual. Another is to use a filter that comes with Camlp4 to “lift” the AST—that is, to generate the AST representing the original AST! Maybe it is easier to try it than to explain it:</p> 
<div class="highlight"><pre><code class="bash">camlp4o to_of_string.cmo -filter Camlp4AstLifter <span class="nb">test</span>.ml
</code></pre> 
</div> 
<p>Now compare the result to the tree you get back from Camlp4’s parser for the code you <em>meant</em> to write, and you can probably spot your mistake.</p> 
<p>(If you tried to redirect the <code>camlp4o</code> command to a file or pipe it through <code>less</code> you got some line noise—this is the marshalled <code>ocamlc</code> AST. By default Camlp4 checks whether its output is a TTY; if so it calls the pretty-printer, if not the <code>ocamlc</code> AST marshaller. To override this use the <code>-printer o</code> option, or <code>-printer r</code> for revised syntax.)</p> 
<b>Other builtin filters</b> 
<p>This <code>Camlp4AstLifter</code> is pretty useful. What else comes with Camlp4? There are several other filters in <code>camlp4/Camlp4Filters</code> which you can call with <code>-filter</code>:</p> 
<ul> 
<li> 
<p><code>Camlp4FoldGenerator</code> generates visitor classes from datatypes. Try putting <code>class x = Camlp4MapGenerator.generated</code> after a type definition. The idea is that you can override methods of the visitor so you can do some transformation on a tree without having to write the boilerplate to walk the parts you don’t care about. In fact, this filter is used as part of the Camlp4 bootstrap to generate vistors for the AST; you can see the <code>map</code> and <code>fold</code> classes in <code>camlp4/Camlp4/Sig.ml</code>.</p> 
</li> 
<li> 
<p><code>Camlp4MetaGenerator</code> generates lifting functions from a type definition—these functions are what <code>Camlp4AstLifter</code> uses to lift the AST, and it’s also how quotations are implemented. I’m planning to cover how to implement quotations / antiquotations (for a different language) in a future post, and <code>Camlp4MetaGenerator</code> will be crucial.</p> 
</li> 
<li> 
<p><code>Camlp4LocationStripper</code> replaces all the locations in an AST with <code>Loc.ghost</code>. I don’t know what this is for, but it might be useful if you wanted to compare two ASTs and be insensitive to their locations.</p> 
</li> 
<li> 
<p><code>Camlp4Profiler</code> inserts profiling code, in the form of function call counts. I haven’t tried it, and I’m not sure when you would want it in preference to gprof.</p> 
</li> 
<li> 
<p><code>Camlp4TrashRemover</code> just filters out a module called <code>Camlp4Trash</code>. Such a module may be found in <code>camlp4/Camlp4/Struct/Camlp4Ast.mlast</code>; I think the idea is that the module is there in order to generate some stuff, but the module itself is not needed.</p> 
</li> 
<li> 
<p><code>Camlp4MapGenerator</code> has been subsumed by <code>Camlp4FoldGenerator</code>.</p> 
</li> 
<li> 
<p><code>Camlp4ExceptionTracer</code> seems to be a special-purpose tool to help debug Camlp4.</p> 
</li> 
</ul> 
<p>OK, maybe not too much useful stuff here, but it is interesting to work out how Camlp4 is bootstrapped.</p> 
<p>I think next time I will get into Camlp4’s extensible parsers, on the way toward syntax extensions.</p> 
<b>Colophon</b> 
<p>I wrote my previous posts in raw HTML, with highlighted code generated from a hightlighted Emacs buffer by <a href="http://fly.cc.fer.hr/~hniksic/emacs/htmlize.el">htmlize.el</a>. Iterating on this setup was unutterably painful. This post was written using <a href="http://github.com/mojombo/jekyll">jekyll</a> with a simple template to approximate the Blogspot formatting, mostly so I can check that lines of code aren’t too long. Jekyll is very nice: you can write text with <a href="http://maruku.rubyforge.org/">Markdown</a>, and highlight code with <a href="http://pygments.org/">Pygments</a>.</p><div class="blogger-post-footer"><img alt="" height="1" src="https://blogger.googleusercontent.com/tracker/1445545651031573301-122123601620369639?l=ambassadortothecomputers.blogspot.com" width="1"/></div></div>
    </summary>
    <updated>2010-03-03T02:09:00Z</updated>
    <category scheme="http://www.blogger.com/atom/ns#" term="camlp4"/>
    <author>
      <name>Jake Donham</name>
      <email>noreply@blogger.com</email>
    </author>
    <source>
      <id>tag:blogger.com,1999:blog-1445545651031573301</id>
      <author>
        <name>Jake Donham</name>
        <email>noreply@blogger.com</email>
      </author>
      <link href="http://ambassadortothecomputers.blogspot.com/" rel="alternate" type="text/html"/>
      <link href="http://ambassadortothecomputers.blogspot.com/feeds/posts/default?alt=rss" rel="self" type="application/atom+xml"/>
      <subtitle>Mostly OCaml.</subtitle>
      <title>Ambassador to the Computers</title>
      <updated>2010-03-09T17:00:29Z</updated>
    </source>
  </entry>

  <entry>
    <id>http://alan.petitepomme.net/cwn/2010.03.02.html</id>
    <link href="http://alan.petitepomme.net/cwn/2010.03.02.html" rel="alternate" type="text/html"/>
    <title>Caml Weekly News, 02 Mar 2010</title>
    <summary>graph of function dependances / OCaml bindings to hivex (Windows Registry hive library) / How to pass C pointers to Caml / Other Caml News</summary>
    <updated>2010-03-02T12:00:00Z</updated>
    <source>
      <id>http://alan.petitepomme.net/cwn/</id>
      <author>
        <name>Caml Weekly News</name>
      </author>
      <link href="http://alan.petitepomme.net/cwn/" rel="alternate" type="text/html"/>
      <link href="http://alan.petitepomme.net/cwn/cwn.rss" rel="self" type="application/rss+xml"/>
      <subtitle>News frow the Caml list</subtitle>
      <title>Caml Weekly News</title>
      <updated>2010-03-09T09:00:08Z</updated>
    </source>
  </entry>

  <entry xml:lang="fr">
    <id>http://dutherenverseauborddelatable.wordpress.com/?p=692</id>
    <link href="http://dutherenverseauborddelatable.wordpress.com/2010/02/26/opa-internships-continued/" rel="alternate" type="text/html"/>
    <title>OPA internships (continued)</title>
    <summary type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">Thanks for all the high-level applications to MLstate’s internships. All positions are now filled.
See you soon for the next release of OPA.
–
Merci pour toutes les (très bonnes) candidatures aux stages que nous avons proposé. Tous les stages ont été pris.
À bientôt pour la prochaine version d’OPA.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dutherenverseauborddelatable.wordpress.com&amp;blog=1202429&amp;post=692&amp;subd=dutherenverseauborddelatable&amp;ref=&amp;feed=1"/></div>
    </summary>
    <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>Thanks for all the high-level applications to MLstate’s internships. All positions are now filled.</p>
<p>See you soon for the next release of OPA.</p>
<p>–</p>
<p>Merci pour toutes les (très bonnes) candidatures aux stages que nous avons proposé. Tous les stages ont été pris.</p>
<p>À bientôt pour la prochaine version d’OPA.</p>
<br/>  <a href="http://feeds.wordpress.com/1.0/gocomments/dutherenverseauborddelatable.wordpress.com/692/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dutherenverseauborddelatable.wordpress.com/692/"/></a> <a href="http://feeds.wordpress.com/1.0/godelicious/dutherenverseauborddelatable.wordpress.com/692/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dutherenverseauborddelatable.wordpress.com/692/"/></a> <a href="http://feeds.wordpress.com/1.0/gostumble/dutherenverseauborddelatable.wordpress.com/692/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dutherenverseauborddelatable.wordpress.com/692/"/></a> <a href="http://feeds.wordpress.com/1.0/godigg/dutherenverseauborddelatable.wordpress.com/692/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dutherenverseauborddelatable.wordpress.com/692/"/></a> <a href="http://feeds.wordpress.com/1.0/goreddit/dutherenverseauborddelatable.wordpress.com/692/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dutherenverseauborddelatable.wordpress.com/692/"/></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dutherenverseauborddelatable.wordpress.com&amp;blog=1202429&amp;post=692&amp;subd=dutherenverseauborddelatable&amp;ref=&amp;feed=1"/></div>
    </content>
    <updated>2010-02-26T19:06:24Z</updated>
    <category term="En fran&#xE7;ais / In French"/>
    <category term="In English / En anglais"/>
    <category term="Informatique / Computer science"/>
    <category term="OCaml"/>
    <category term="OPA"/>
    <category term="Recherche / Research"/>
    <category term="Stage"/>
    <category term="offre d'emploi"/>
    <category term="ajax"/>
    <category term="applications"/>
    <category term="comet"/>
    <category term="concurrency"/>
    <category term="distribution"/>
    <category term="f#"/>
    <category term="haskell"/>
    <category term="higher-order programming"/>
    <category term="informatique"/>
    <category term="internship"/>
    <category term="lambda"/>
    <category term="parall&#xE9;lisme"/>
    <category term="programmation"/>
    <category term="programming"/>
    <category term="programming languages"/>
    <category term="real-time web"/>
    <category term="stage"/>
    <category term="web 2.0"/>
    <author>
      <name>yoric</name>
    </author>
    <source>
      <id>http://dutherenverseauborddelatable.wordpress.com</id>
      <logo>http://www.gravatar.com/blavatar/b4f8dbeb495eaa4c8ee77515c06383c8?s=96&amp;d=http://s2.wp.com/i/buttonw-com.png</logo>
      <link href="http://dutherenverseauborddelatable.wordpress.com/category/ocaml/feed/" rel="self" type="application/atom+xml"/>
      <link href="http://dutherenverseauborddelatable.wordpress.com" rel="alternate" type="text/html"/>
      <link href="http://dutherenverseauborddelatable.wordpress.com/osd.xml" rel="search" type="application/opensearchdescription+xml"/>
      <subtitle>De l'actualité, de l'informatique, de l'enseignement, d'intenses réflexions et quelques autres absurdités</subtitle>
      <title>Il y a du thé renversé au bord de la table » OCaml</title>
      <updated>2010-02-26T20:00:18Z</updated>
    </source>
  </entry>
</feed>
