<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Alp Mestan's Corner &#187; OCaml</title>
	<atom:link href="http://blog.mestan.fr/feed/?cat=16" rel="self" type="application/rss+xml" />
	<link>http://blog.mestan.fr</link>
	<description>My programming, AI and Maths stuffs</description>
	<pubDate>Thu, 24 Sep 2009 21:10:42 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Bouncing Ball in OCaml with OCamlSDL</title>
		<link>http://blog.mestan.fr/2009/04/28/bouncing-ball-in-ocaml-with-ocamlsdl/</link>
		<comments>http://blog.mestan.fr/2009/04/28/bouncing-ball-in-ocaml-with-ocamlsdl/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 22:16:48 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[bouncing ball]]></category>

		<category><![CDATA[OCamlSDL]]></category>

		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=31</guid>
		<description><![CDATA[Hi,
I&#8217;ve written a little boucing ball program in OCaml with OCamlSDL.
It can be used as a basis to write a Pong game, or any 2D game with a ball bouncing here and there on the screen.
You can download it (images, font, source code and Makefile included) here : bbsdl.tar.gz.
Don&#8217;t forget to tell me if you [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve written a little boucing ball program in OCaml with OCamlSDL.<br />
It can be used as a basis to write a Pong game, or any 2D game with a ball bouncing here and there on the screen.<br />
You can download it (images, font, source code and Makefile included) here : <a href="http://mestan.fr/ocaml/bbsdl/bbsdl.tar.gz">bbsdl.tar.gz</a>.</p>
<p>Don&#8217;t forget to tell me if you start using it.<br />
By the way, I&#8217;ve put some comments in the code for learning purpose, as it has been my first OCamlSDL application so it may be of help for OCaml hackers.</p>
<p><a href='http://blog.mestan.fr/wp-content/bbsdl.png'><img src="http://blog.mestan.fr/wp-content/bbsdl.png" alt="Bouncing Ball in OCamlSDL" title="bbsdl" width="400" height="316" class="aligncenter size-full wp-image-32" /></a></p>
<p>Enjoy.</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/04/28/bouncing-ball-in-ocaml-with-ocamlsdl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Using OCaml&#8217;s module functors to provide monadic contexts for Batteries</title>
		<link>http://blog.mestan.fr/2009/04/24/using-ocamls-module-functors-to-provide-monadic-contexts-for-batteries/</link>
		<comments>http://blog.mestan.fr/2009/04/24/using-ocamls-module-functors-to-provide-monadic-contexts-for-batteries/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 17:29:35 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[Haskell]]></category>

		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Prolog]]></category>

		<category><![CDATA[Scientific Computing]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[batteries]]></category>

		<category><![CDATA[enum]]></category>

		<category><![CDATA[functor]]></category>

		<category><![CDATA[included]]></category>

		<category><![CDATA[module]]></category>

		<category><![CDATA[monads]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=30</guid>
		<description><![CDATA[Hi,
Several days ago, bluestorm and I started working on monads-related stuffs for Batteries, so that we&#8217;d be able to provide a good API for writing and using monads in Objective Caml.
Well, we&#8217;ve now written the basis of the future monad-related functions and modules in Batteries.
Of course, we&#8217;ve introduced two key monads, keeping Batteries&#8217; spirit : [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Several days ago, bluestorm and I <a href="http://lists.forge.ocamlcore.org/pipermail/batteries-devel/2009-April/000703.html">started working on monads-related stuffs for Batteries</a>, so that we&#8217;d be able to provide a good API for writing and using monads in Objective Caml.</p>
<p>Well, we&#8217;ve now written the basis of the future monad-related functions and modules in Batteries.</p>
<p>Of course, we&#8217;ve introduced two key monads, keeping Batteries&#8217; spirit : the Option monad and the Enum monad. The first is the equivalent of Haskell&#8217;s Maybe monad, whereas the latter is somehow &#8220;equivalent&#8221; to Haskell&#8217;s List monad, with the difference that Batteries&#8217; key data structure is Enum, whereas Haskell&#8217;s standard library&#8217;s is List.</p>
<p>We&#8217;ve also written two key functions for working with monads&#8230; If you are familiar with foldM and sequence in Haskell, working over lists, you won&#8217;t be lost when using our fold_monad and sequence functions, working over enums.</p>
<p>Hey, wait a minute&#8230;<br />
<span id="more-30"></span></p>
<p>OCaml&#8217;s hasn&#8217;t typeclasses ! How can we &#8220;overload&#8221; bind and return and make sequence and fold_monac guess what is the monad they have to work in ?<br />
The answer is <a href="http://alain.frisch.fr/soft#openin">the pa_openin syntax extension</a>.</p>
<p>Now, even if we&#8217;re working on adding some trivial uses of our monad related stuffs in Batteries&#8217; testsuite, you can take a look at the following sample which works on my local Batteries version&#8230;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p30code2'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p302"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p30code2"><pre class="ocaml" style="font-family:monospace;"><span style="color: #a52a2a;">#</span> <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">module</span> M <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">Option</span><span style="color: #a52a2a;">.</span><span style="color: #060;">Monad</span> <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">open</span> Enum<span style="color: #a52a2a;">.</span><span style="color: #060;">WithMonad</span><span style="color: #6c6;">&#40;</span>M<span style="color: #6c6;">&#41;</span>,M <span style="color: #06c; font-weight: bold;">in</span>
       sequence <span style="color: #6c6;">&#91;</span>? Some x <span style="color: #a52a2a;">|</span>x <span style="color: #a52a2a;">&lt;-</span> <span style="color: #c6c;">1</span><span style="color: #a52a2a;">--</span><span style="color: #c6c;">100</span> <span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">;;</span>
<span style="color: #a52a2a;">-</span> <span style="color: #a52a2a;">:</span> int Batteries<span style="color: #a52a2a;">.</span><span style="color: #060;">Enum</span><span style="color: #a52a2a;">.</span><span style="color: #060;">t</span> <span style="color: #06c; font-weight: bold;">option</span> <span style="color: #a52a2a;">=</span> Some <span style="color: #a52a2a;">&lt;</span>abstr<span style="color: #a52a2a;">&gt;</span>
<span style="color: #a52a2a;">#</span> <span style="color: #06c; font-weight: bold;">let</span> <span style="color: #06c; font-weight: bold;">module</span> M <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">Option</span><span style="color: #a52a2a;">.</span><span style="color: #060;">Monad</span> <span style="color: #06c; font-weight: bold;">in</span> <span style="color: #06c; font-weight: bold;">open</span> Enum<span style="color: #a52a2a;">.</span><span style="color: #060;">WithMonad</span><span style="color: #6c6;">&#40;</span>M<span style="color: #6c6;">&#41;</span>,M <span style="color: #06c; font-weight: bold;">in</span>
       sequence <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">List</span><span style="color: #a52a2a;">.</span><span style="color: #060;">enum</span> <span style="color: #6c6;">&#91;</span>Some <span style="color: #c6c;">1</span><span style="color: #a52a2a;">;</span> None <span style="color: #a52a2a;">;</span> Some <span style="color: #c6c;">3</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;;</span>
<span style="color: #a52a2a;">-</span> <span style="color: #a52a2a;">:</span> int Batteries<span style="color: #a52a2a;">.</span><span style="color: #060;">Enum</span><span style="color: #a52a2a;">.</span><span style="color: #060;">t</span> <span style="color: #06c; font-weight: bold;">option</span> <span style="color: #a52a2a;">=</span> None</pre></td></tr></table></div>

<p>By the way, do you think, you, user, the (>>=) operator should be provided by default in our XXX.Monad modules ? </p>
<p>Enjoy !</p>
<p>[Link : <a href="http://git.ocamlcore.org/cgi-bin/gitweb.cgi?p=batteries/batteries.git;a=commit;h=e4564299fb4daef2dffd1bf6787b360dc5f61a6e">my git commit</a>]</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/04/24/using-ocamls-module-functors-to-provide-monadic-contexts-for-batteries/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Review of OCaml Journal articles : Low-level optimization tips and tricks</title>
		<link>http://blog.mestan.fr/2009/04/09/review-of-ocaml-journal-articles-low-level-optimization-tips-and-tricks/</link>
		<comments>http://blog.mestan.fr/2009/04/09/review-of-ocaml-journal-articles-low-level-optimization-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 12:17:11 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Scientific Computing]]></category>

		<category><![CDATA[articles]]></category>

		<category><![CDATA[efficiency]]></category>

		<category><![CDATA[ffconsultancy]]></category>

		<category><![CDATA[harrop]]></category>

		<category><![CDATA[journal]]></category>

		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=29</guid>
		<description><![CDATA[Hi,
Jon Harrop has written many articles in his OCaml Journal, and some of them are related to low-level optimization, which is a very important topic for OCaml developers, as OCaml is a fast functional language and can race against mainstream languages if we help him with our way of writing code, using the compiler, etc.
These [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Jon Harrop has written many articles in his <a href="http://www.ffconsultancy.com/products/ocaml_journal/">OCaml Journal</a>, and some of them are related to low-level optimization, which is a very important topic for OCaml developers, as OCaml is a fast functional language and can race against mainstream languages if we help him with our way of writing code, using the compiler, etc.</p>
<p>These articles cover many aspects of optimizations, of different kind :</p>
<ul>
<li>Architecture</li>
<li>Compiler manipulation (flags, etc)</li>
<li>Allocation</li>
<li>Deforesting (elimination of intermediate data structures)</li>
<li>Copies</li>
<li>Boxing</li>
<li>Mutation</li>
<li>Garbage collection</li>
<li><em>and so on&#8230;</em></li>
</ul>
<p>As I&#8217;m often doing some &#8220;races&#8221; between OCaml and other languages (Haskell, C++, Java, &#8230;), it has been very interesting for me and I managed to write equivalent applications where OCaml was winning &#8220;the race&#8221;, together with C++, generally. I&#8217;ve been programming in C++ for 6 years now and know many optimizations-related stuffs in C++. But learning this kind of things for OCaml was very interesting but also <strong>important</strong> for me. Moreover, you know, when you like a programming language, you often want to discover its &#8220;underground&#8221;, know it just well so that you&#8217;ll exactly know what your code will generate. </p>
<p>With functional programming languages, however, it&#8217;s easier to have an idea of what will be generated by the compiler, but if you don&#8217;t read about such things, you&#8217;ll never be able to guess. I think as there&#8217;s not that much documentation about OCaml but the official reference manual, Jon&#8217;s work is really valuable and is (and would) be of help for many OCaml developers.</p>
<p>These articles have really helped me with discovering OCaml&#8217;s underground and were very useful for projects I&#8217;m working on, in OCaml of course. Why not for you ?</p>
<p>PS : Comments are closed. Don&#8217;t loose your time criticizing anyone. Thanks. But you can e-mail me for discussing it (same adress than on mailing lists).</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/04/09/review-of-ocaml-journal-articles-low-level-optimization-tips-and-tricks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Who thought OCaml was dead ?!</title>
		<link>http://blog.mestan.fr/2009/04/06/who-thought-ocaml-was-dead/</link>
		<comments>http://blog.mestan.fr/2009/04/06/who-thought-ocaml-was-dead/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 20:09:10 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[batteries]]></category>

		<category><![CDATA[debian]]></category>

		<category><![CDATA[french-government-should-stop-its-mess]]></category>

		<category><![CDATA[included]]></category>

		<category><![CDATA[library]]></category>

		<category><![CDATA[standard]]></category>

		<category><![CDATA[testing]]></category>

		<category><![CDATA[unstable]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=28</guid>
		<description><![CDATA[Hi,
I&#8217;m writing this post because I want to thank and encourage the OCaml community. Indeed, there are many really *great* news this week that you may have seen if you read either Planet OCaml(Core), the Caml mailing list or both.
OCaml and Debian &#8212; The first one is a very good one for making OCaml more [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m writing this post because I want to thank and encourage the OCaml community. Indeed, there are many really *great* news this week that you may have seen if you read either Planet OCaml(Core), the Caml mailing list or both.</p>
<p><strong>OCaml and Debian</strong> &#8212; The first one is a very good one for making OCaml more popular, more easy to install, etc : <a href="http://upsilon.cc/~zack/blog/posts/2009/04/ocaml_3.11_in_testing/">The OCaml 3.11 Debian package is now in Debian&#8217;s official testing repository</a> ! Yeah ! I really congratulate the debian-ocaml maintainer team for the huge work. Considering nearly all installations of Debian stable are for server-like usages, having the package in testing make it easier to install OCaml and get it installed and configured in two seconds for all desktop users of Debian (and Debian-based distributions). Indeed, everything will be done with a single root command :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p28code4'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p284"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p28code4"><pre class="shell" style="font-family:monospace;"># aptitude install ocaml</pre></td></tr></table></div>

<p>That&#8217;s all.</p>
<p><strong>OCaml Batteries Included</strong> &#8212; <a href="http://dutherenverseauborddelatable.wordpress.com/2009/04/06/ocaml-batteries-included-beta-1/">OCaml Batteries Included Beta 1 is out !</a> If you still don&#8217;t know about it, you should quickly go on <a href="http://batteries.forge.ocamlcore.org/">its website on OCamlCore</a>, download it and install it and then read the documentation for an introduction and a reference manual of Batteries. You can also take the <strong>ocaml-batteries-included</strong> package on Debian&#8217;s unstable repos.<br />
The Beta 1 is already having its first feedbacks and already provide a huge amount of necessary modules and functions, with some syntax extensions and tools for making programming with Batteries the easier possible ! OCaml was criticized because of its standard library, lacking of many additional stuffs that are in Haskell&#8217;s SL. Now, it&#8217;s over. Batteries is easy to install, easy to use and provide a great new-standard-library. Come on, test it and give some feedback.</p>
<p>Cheers guys !</p>
<p>BTW, the French government still ignores problem related to the reforms about Universities and Research. They&#8217;re killing the whole University concept and system and still ignoring that great Researchers are working for a really bad salary, in bad conditions even if they&#8217;ve studied 8 years long at least and that there are people paid much more than what Researchers are, for much easier and cool works&#8230; Strikes goes on, we must save our Universities !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/04/06/who-thought-ocaml-was-dead/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An OCaml IRC toplevel - Some other news</title>
		<link>http://blog.mestan.fr/2009/03/31/an-ocaml-irc-toplevel-some-other-news/</link>
		<comments>http://blog.mestan.fr/2009/03/31/an-ocaml-irc-toplevel-some-other-news/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 20:54:09 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Scientific Computing]]></category>

		<category><![CDATA[hlvm]]></category>

		<category><![CDATA[irc]]></category>

		<category><![CDATA[jane]]></category>

		<category><![CDATA[mlbot]]></category>

		<category><![CDATA[ocamlc]]></category>

		<category><![CDATA[project]]></category>

		<category><![CDATA[street]]></category>

		<category><![CDATA[summer]]></category>

		<category><![CDATA[toplevel]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=27</guid>
		<description><![CDATA[Hi,
It&#8217;s been some days I was working on a very interesting project&#8230;
Many of you probably know Internet Relay Chat (IRC), in particular the Freenode network. You can access it through an IRC Client, the most known being XChat. The host is irc.freenode.net, on port 6667.
Some of you are used to bots on IRC, often provided [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>It&#8217;s been some days I was working on a very interesting project&#8230;<br />
Many of you probably know Internet Relay Chat (IRC), in particular the <a href="http://freenode.net/">Freenode</a> network. You can access it through an IRC Client, the most known being XChat. The host is <em>irc.freenode.net</em>, on port <em>6667</em>.<br />
Some of you are used to <strong>bots</strong> on IRC, often provided by regular IRC users, for their prefered language/tool/etc. There is <strong>lambdabot</strong> on the #haskell channel, <strong>geordi</strong> on the ##C++ channel, etc. I&#8217;ve also seen that <em>Richard WM Jones</em> had worked on a similar bot for the #ocaml channel, <em>xavierbot</em>. But I wasn&#8217;t quite satisfied with it as it was nearly not written in OCaml, and I also wanted to develop one myself.</p>
<p>And&#8230; it&#8217;s done ! I&#8217;m proud to introduce you <strong>mlbot</strong>, written in OCaml, for OCaml, in 144 LoC for the moment. The code will be online soon on mlbot&#8217;s webpage : <a href="http://mestan.fr/ocaml/mlbot/">http://mestan.fr/ocaml/mlbot/</a></p>
<p>Here is an example of interaction with mlbot :</p>
<blockquote><p>&lt;Alpounet&gt; > List.fold_right (+) [1;2;3;4;5] 0 ;;<br />
&lt;mlbot&gt; - : int = 15<br />
&lt;Alpounet&gt; > &#8220;1&#8243; + 1 ;;<br />
&lt;mlbot&gt; Type Error<br />
&lt;Yoric[DT]&gt; > &#8221; *_o/* MLBot, c&#8217;est cool, *\\o_*&#8221;;;<br />
&lt;mlbot&gt; - : string = &#8221; *_o/* MLBot, c&#8217;est cool, *\\o_*&#8221;
</p></blockquote>
<p>For the moment,  mlbot is only on the following channels, still on Freenode : #ocaml-fr and #mlbot, but will be soon on #ocaml when I&#8217;ll have finished some security improvements.</p>
<p>By the way, my Jane Street Summer Project application has been sent this morning, after many discussions with many people of the OCaml community that have helped and encouraged me : David Teller, Jon Harrop, Xavier Leroy and my computability professor, Grégory Lafitte.<br />
This project will be about HLVM (<a href="http://hlvm.forge.ocamlcore.org/">http://hlvm.forge.ocamlcore.org/</a>) and the OCaml language. Stay tuned !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/03/31/an-ocaml-irc-toplevel-some-other-news/feed/</wfw:commentRss>
		</item>
		<item>
		<title>OCaml and -dlambda #1</title>
		<link>http://blog.mestan.fr/2009/03/22/ocaml-and-dlambda-1/</link>
		<comments>http://blog.mestan.fr/2009/03/22/ocaml-and-dlambda-1/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 10:29:00 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[lambda]]></category>

		<category><![CDATA[ocamlc]]></category>

		<category><![CDATA[ocamlopt]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=26</guid>
		<description><![CDATA[Hi,
Have you ever tried compiling with either ocamlc or ocamlopt with the -dlambda option ?
Compiling the following code :

?View Code OCAML1
2
3
4
5
let f = List.map &#40;fun x -&#62; x+1&#41;
&#160;
let print_list = List.iter &#40;fun x -&#62; Printf.printf &#34; %d &#34; x&#41;
&#160;
let _ = print_list &#40; f &#91;1;2;3;4;5&#93; &#41;

give the following &#8220;lambda code&#8221; :

?View Code LAMBDA1
2
3
4
5
6
7
8
9
10
11
12
13
(* $ ocamlc [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Have you ever tried compiling with either ocamlc or ocamlopt with the <em>-dlambda</em> option ?</p>
<p>Compiling the following code :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p26code8'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p268"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p26code8"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> f <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">List</span><span style="color: #a52a2a;">.</span><span style="color: #060;">map</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> x <span style="color: #a52a2a;">-&gt;</span> x<span style="color: #a52a2a;">+</span><span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> print_list <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">List</span><span style="color: #a52a2a;">.</span><span style="color: #060;">iter</span> <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">fun</span> x <span style="color: #a52a2a;">-&gt;</span> <span style="color: #06c; font-weight: bold;">Printf</span><span style="color: #a52a2a;">.</span><span style="color: #060;">printf</span> <span style="color: #3cb371;">&quot; %d &quot;</span> x<span style="color: #6c6;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> _ <span style="color: #a52a2a;">=</span> print_list <span style="color: #6c6;">&#40;</span> f <span style="color: #6c6;">&#91;</span><span style="color: #c6c;">1</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">2</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">3</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">4</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">5</span><span style="color: #6c6;">&#93;</span> <span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<p>give the following &#8220;lambda code&#8221; :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p26code9'); return false;">View Code</a> LAMBDA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p269"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p26code9"><pre class="lambda" style="font-family:monospace;">(* $ ocamlc -dlambda test.ml *)
(setglobal Test!
  (let
    (f/58
       (function l/59
         (apply (field 10 (global List!)) (function x/60 (+ x/60 1)) l/59))
     print_list/61
       (apply (field 9 (global List!))
         (function x/62 (apply (field 1 (global Printf!)) &quot; %d &quot; x/62))))
    (seq
      (apply print_list/61
        (apply f/58 [0: 1 [0: 2 [0: 3 [0: 4 [0: 5 0a]]]]]))
      (makeblock 0 f/58 print_list/61))))</pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p26code10'); return false;">View Code</a> LAMBDA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2610"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p26code10"><pre class="lambda" style="font-family:monospace;">(* $ ocamlopt -dlambda las.ml *)
(seq
  (let
    (f/58
       (function l/59
         (apply (field 10 (global List!)) (function x/60 (+ x/60 1)) l/59)))
    (setfield_imm 0 (global Test!) f/58))
  (let
    (print_list/61
       (apply (field 9 (global List!))
         (function x/62 (apply (field 1 (global Printf!)) &quot; %d &quot; x/62))))
    (setfield_imm 1 (global Test!) print_list/61))
  (apply (field 1 (global Test!))
    (apply (field 0 (global Test!)) [0: 1 [0: 2 [0: 3 [0: 4 [0: 5 0a]]]]]))
  0a)</pre></td></tr></table></div>

<p>There are many phases in the compilation process, and the lambda generation phase is the last before either bytecode/native code generation.</p>
<p>&#8216;global&#8217; keyword seems to reference modules (Test is the module of my file, because of the name, test.ml).<br />
&#8216;apply&#8217; just does function calls.<br />
&#8216;field&#8217; seems to reference function in modules, like index references values in arrays.</p>
<p>More in the next exploration of the -dlambda option !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/03/22/ocaml-and-dlambda-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Diving into Batteries #2 : Heavyweight strings</title>
		<link>http://blog.mestan.fr/2009/03/12/diving-into-batteries-2-heavyweight-strings/</link>
		<comments>http://blog.mestan.fr/2009/03/12/diving-into-batteries-2-heavyweight-strings/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 11:57:53 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[batteries]]></category>

		<category><![CDATA[included]]></category>

		<category><![CDATA[ropes]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=25</guid>
		<description><![CDATA[Today, we&#8217;ll give a whirl at the Rope module of OCaml Batteries Included.
What are ropes ? 
Ropes are better strings (but heavyweight) :

The length of a rope can be determined in constant time
appending or prepending a small rope to an arbitrarily large one in amortized constant time
concat, substring, insert, remove operations in amortized logarithmic time
access [...]]]></description>
			<content:encoded><![CDATA[<p>Today, we&#8217;ll give a whirl at the Rope module of <a href="http://batteries.forge.ocamlcore.org/">OCaml Batteries Included</a>.</p>
<p>What are <em>ropes</em> ? </p>
<p>Ropes are better strings (but heavyweight) :</p>
<li>
<ul>The length of a <strong>rope</strong> can be determined in constant time</ul>
<ul>appending or prepending a small rope to an arbitrarily large one in amortized constant time</ul>
<ul>concat, substring, insert, remove operations in amortized logarithmic time</ul>
<ul>access to and modification of ropes in logarithmic time</ul>
</li>
<p>Moreover, functional purity is preserved, we do never modify the original rope when appending, inserting, removing, etc.<br />
There&#8217;ll just be as much as possible data shared between the resulting string and the original one.</p>
<p>However, world is not pink-made. I quote the documentation :</p>
<blockquote><p>However, Rope is an amortized data structure, and its use in a persistent setting can easily degrade its amortized time bounds. It is thus mainly intended to be used ephemerally. In some cases, it is possible to use Rope persistently with the same amortized bounds by explicitly rebalancing ropes to be reused using balance. Special care must be taken to avoid calling balance too frequently; in the limit, calling balance after each modification would defeat the purpose of amortization. </p></blockquote>
<p>First, you have to know that a syntax extension is included in Batteries, such that you can create literal ropes instead of strings just by prefixing the litteral string with &#8216;r&#8217;. Let&#8217;s now see how we can create a rope containing the &#8220;OCaml Batteries Included&#8221; string.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p25code12'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2512"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p25code12"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> my_first_rope <span style="color: #a52a2a;">=</span> r<span style="color: #3cb371;">&quot;OCaml Batteries Included&quot;</span> <span style="color: #a52a2a;">;;</span></pre></td></tr></table></div>

<p>The type of &#8216;my_first_rope&#8217; is Batteries.Rope.t, that&#8217;s to say a rope.</p>
<p>Of course, there are many conversions possible from and to ropes. from/to_string, from/to_ustring, of_char, of_uchar, of_latin1, and also many interactions possible with the Enum module. You can also lowercase and uppercase a rope, make a rope of &#8216;n&#8217; times a given character &#8216;c&#8217;.</p>
<p>As you may expect, there are many string operations included in this module. You can explode a string into a character list, you can split a rope using a given separator, get the character at a given position, remove characters, insert characters, concatenate ropes, </p>
<p>OCaml programming, and more generally functional programming, is empowered by higher order functions. The Rope module uses it, providing us higher order functions like iter[...], range_iter[...], fold, map, filter, filter_map, etc. This way, we can express shortly in our code very complex operations with these higher order functions, which let us work on strings with power, speed and elegance.</p>
<p>There are many other functions that fulfill (personally) all the needs I have from a string manipulation module.</p>
<p>To conclude, there are many &#8220;bulk&#8221; variants of functions that let us work more efficiently for large chunks of string data.</p>
<p>I think it is useless to give code using Batteries&#8217; ropes, you should rather go to <a href="http://batteries.forge.ocamlcore.org/doc.preview:batteries-alpha3/html/api/Rope.html">the corresponding documentation page</a> and try it out !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/03/12/diving-into-batteries-2-heavyweight-strings/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Diving into Batteries #1 : Comprehension</title>
		<link>http://blog.mestan.fr/2009/02/23/diving-into-batteries-1-comprehension/</link>
		<comments>http://blog.mestan.fr/2009/02/23/diving-into-batteries-1-comprehension/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 11:28:32 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[batteries]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=23</guid>
		<description><![CDATA[Hi,
I&#8217;m back here to introduce a very promising project : OCaml Batteries Included.
It aims at putting together all the things we may need as OCaml developers in a standard library. It has already put together some existing modules (Extlib, etc) and is now growing up with totally new modules.
The first thing you have to know [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m back here to introduce a very promising project : <strong>OCaml Batteries Included</strong>.</p>
<p>It aims at putting together all the things we may need as OCaml developers in a standard library. It has already put together some existing modules (Extlib, etc) and is now growing up with totally new modules.</p>
<p>The first thing you have to know is that with such standardization efforts, the aim is really to get OCaml programming funnier and easier, with strong and efficient modules helping us in everyday-programming. Moreover, there are some syntax extensions that were really missing in OCaml like the one I&#8217;m going to tell about : Comprehension.<br />
<span id="more-23"></span><br />
<strong>What is Comprehension ?</strong></p>
<p>You may probably know better expressions like &#8220;List comprehension&#8221; ? In fact, OCaml Batteries Included (also called Batteries) provide us something more general than List comprehensions. The aim of such techniques is to, given an expression, a &#8220;data domain&#8221; and, if wanted, constraints, expand the expression to a set (not in its mathematical sense) of data of the form of the given expression, based on elements that belong to their respective domains and respect their respective constraints. It uses by default an Enum interface for building comprehension of any data container that provide some precise functions. Python or Haskell developers, e.g, may be used to List comprehension. It lets us write such codes, in Haskell :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code21'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2321"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code21"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#91;</span> x<span style="color: #339933; font-weight: bold;">*</span><span style="color: red;">2</span> <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">3</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">4</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">5</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">6</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">7</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">8</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">9</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: red;">10</span><span style="color: green;">&#93;</span> <span style="color: green;">&#93;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code22'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2322"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code22"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#91;</span> x<span style="color: #339933; font-weight: bold;">*</span>x <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>100<span style="color: green;">&#93;</span> <span style="color: green;">&#93;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code23'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2323"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code23"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#91;</span> x<span style="color: #339933; font-weight: bold;">*</span>y <span style="color: #339933; font-weight: bold;">-</span> x <span style="color: #339933; font-weight: bold;">-</span> y <span style="color: #339933; font-weight: bold;">|</span> x <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>100<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">,</span> y <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span>1<span style="color: #339933; font-weight: bold;">..</span>100<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">,</span> x<span style="color: #339933; font-weight: bold;">+</span>y <span style="color: #339933; font-weight: bold;">&lt;</span> <span style="color: red;">40</span> <span style="color: green;">&#93;</span></pre></td></tr></table></div>

<p>Now, it is possible in OCaml using Batteries to write such code, in a very similar way :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code24'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2324"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code24"><pre class="ocaml" style="font-family:monospace;"><span style="color: #6c6;">&#91;</span>? x<span style="color: #a52a2a;">*</span><span style="color: #c6c;">2</span> <span style="color: #a52a2a;">|</span> x <span style="color: #a52a2a;">&lt;-</span> <span style="color: #06c; font-weight: bold;">List</span> <span style="color: #a52a2a;">:</span> <span style="color: #6c6;">&#91;</span><span style="color: #c6c;">1</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">2</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">3</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">4</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">5</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">6</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">7</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">8</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">9</span><span style="color: #a52a2a;">;</span><span style="color: #c6c;">10</span><span style="color: #6c6;">&#93;</span> <span style="color: #6c6;">&#93;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code25'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2325"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code25"><pre class="ocaml" style="font-family:monospace;"><span style="color: #6c6;">&#91;</span>? x<span style="color: #a52a2a;">*</span>x <span style="color: #a52a2a;">+</span> <span style="color: #c6c;">1</span> <span style="color: #a52a2a;">|</span> x <span style="color: #a52a2a;">&lt;-</span> <span style="color: #c6c;">1</span><span style="color: #a52a2a;">--</span><span style="color: #c6c;">100</span> <span style="color: #6c6;">&#93;</span></pre></td></tr></table></div>


<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code26'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2326"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p23code26"><pre class="ocaml" style="font-family:monospace;"><span style="color: #6c6;">&#91;</span>? x<span style="color: #a52a2a;">*</span>y <span style="color: #a52a2a;">-</span> x <span style="color: #a52a2a;">-</span> y <span style="color: #a52a2a;">|</span> x <span style="color: #a52a2a;">&lt;-</span> <span style="color: #c6c;">1</span><span style="color: #a52a2a;">--</span><span style="color: #c6c;">100</span> <span style="color: #a52a2a;">;</span> y <span style="color: #a52a2a;">&lt;-</span> <span style="color: #c6c;">1</span><span style="color: #a52a2a;">--</span><span style="color: #c6c;">100</span><span style="color: #a52a2a;">;</span> x<span style="color: #a52a2a;">+</span>y <span style="color: #a52a2a;">&lt;</span> <span style="color: #c6c;">40</span> <span style="color: #6c6;">&#93;</span></pre></td></tr></table></div>

<p>We can achieve such work on Lists, Arrays, Lazy Lists, &#8230;</p>
<p>Moreover, we can specify the container type we want to get after the &#8220;comprehension&#8221;, as we can see in the documentation of Batteries :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code27'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2327"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p23code27"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> positive_array_of_enum e <span style="color: #a52a2a;">=</span>
  <span style="color: #6c6;">&#91;</span>? <span style="color: #06c; font-weight: bold;">Array</span> <span style="color: #a52a2a;">:</span> n <span style="color: #a52a2a;">|</span> n <span style="color: #a52a2a;">&lt;-</span> e<span style="color: #a52a2a;">;</span> n <span style="color: #a52a2a;">&gt;</span> <span style="color: #c6c;">0</span> <span style="color: #6c6;">&#93;</span></pre></td></tr></table></div>

<p>In fact, the most powerful feature of the comprehension feature in OCaml Batteries Included is that it relies only on the presence of some functions in the data container module :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p23code28'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2328"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p23code28"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">val</span> filter <span style="color: #a52a2a;">:</span> <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">'</span>a <span style="color: #a52a2a;">-&gt;</span> bool<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t
<span style="color: #06c; font-weight: bold;">val</span> concat <span style="color: #a52a2a;">:</span> <span style="color: #a52a2a;">'</span>a t t <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t
<span style="color: #06c; font-weight: bold;">val</span> map <span style="color: #a52a2a;">:</span> <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">'</span>a <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>b<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>b t
<span style="color: #06c; font-weight: bold;">val</span> filter_map <span style="color: #a52a2a;">:</span> <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">'</span>a <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>b <span style="color: #06c; font-weight: bold;">option</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>b t <span style="color: #5d478b; font-style: italic;">(* used for refutable patterns in generators *)</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">val</span> enum <span style="color: #a52a2a;">:</span> <span style="color: #a52a2a;">'</span>a t <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a Enum<span style="color: #a52a2a;">.</span><span style="color: #060;">t</span>
<span style="color: #06c; font-weight: bold;">val</span> of_enum <span style="color: #a52a2a;">:</span> <span style="color: #a52a2a;">'</span>a Enum<span style="color: #a52a2a;">.</span><span style="color: #060;">t</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #a52a2a;">'</span>a t</pre></td></tr></table></div>

<p>where <em>&#8216;a</em> is the type of the values you are enumerating, and <em>&#8216;a t</em> is the data container type : &#8216;a array, &#8216;a Enum.t, &#8216;a list, etc.</p>
<p>However, providing only enum and of_enum will let you work quite well (but not perfectly) with the comprehension extension, interacting with the Enum module.</p>
<p>I hope this feature has caught your interest.</p>
<p>Here are some links about OCaml Batteries Included and this Comprehension feature.<br />
<a href="http://batteries.forge.ocamlcore.org/">OCaml Batteries Included&#8217;s page on OCamlCore.org</a><br />
<a href="http://batteries.forge.ocamlcore.org/doc.preview:batteries-alpha3/html/extensions.html">The syntax extensions page of Batteries, including some details about Comprehension</a><br />
<a href="http://batteries.forge.ocamlcore.org/doc.preview:batteries-alpha3/html/setup.html">Batteries&#8217; install guide</a></p>
<p>This project is a community project, so I adress thanks to all the contributors of Batteries, but special thanks go to <a href="http://www.univ-orleans.fr/lifo/Members/David.Teller/">David Teller</a> for his leading and huge participation on OCaml Batteries Included, and to Gabriel Scherer for his participation and for telling me about this project. And, of course, any contribution to this project is welcome.</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/02/23/diving-into-batteries-1-comprehension/feed/</wfw:commentRss>
		</item>
		<item>
		<title>OCaml completion, reloaded</title>
		<link>http://blog.mestan.fr/2009/02/22/ocaml-completion-reloaded/</link>
		<comments>http://blog.mestan.fr/2009/02/22/ocaml-completion-reloaded/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 21:13:19 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[emacs]]></category>

		<category><![CDATA[tuareg-mode]]></category>

		<category><![CDATA[yasnippet]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=22</guid>
		<description><![CDATA[Hi,
Few days ago, I posted about completion for OCaml programers within Emacs, the best editor ever (Ok, ok, &#8220;one of the best&#8221;), using YASnippets and tuareg-mode. Remember, it was here.
After some discussions with Laurent Le Brun, I post here with a new version of this work. 
Indeed, Laurent liked this work and has worked on [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Few days ago, I posted about completion for OCaml programers within Emacs, the best editor ever (Ok, ok, &#8220;one of the best&#8221;), using YASnippets and tuareg-mode. Remember, it was <a href="http://blog.mestan.fr/2009/02/17/ocaml-completion-within-emacs-with-yasnippet-and-tuareg-mode/">here</a>.</p>
<p>After some discussions with <a href="http://laurent.le-brun.eu/">Laurent Le Brun</a>, I post here with a new version of this work. </p>
<p>Indeed, Laurent liked this work and has worked on it, modifying the original indentation in my snippets, and bringing on new snippets (To be honest, I must tell you that the snippets for imperative programming in OCaml were brought in my Laurent &#8212; I just could not do such a thing !). Then, I&#8217;ve added few things and come back to you with a new archive containing the whole work we&#8217;ve done so far.</p>
<p>To download it, just click <a href="http://mestan.fr/ocaml/emacs/yasnippet-tuareg-mode-0.2.tgz">here</a>.</p>
<p>Thanks and as usual, feedbacks are welcome ! </p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/02/22/ocaml-completion-reloaded/feed/</wfw:commentRss>
		</item>
		<item>
		<title>OCaml &#8216;completion&#8217; within Emacs with YASnippet and tuareg-mode</title>
		<link>http://blog.mestan.fr/2009/02/17/ocaml-completion-within-emacs-with-yasnippet-and-tuareg-mode/</link>
		<comments>http://blog.mestan.fr/2009/02/17/ocaml-completion-within-emacs-with-yasnippet-and-tuareg-mode/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 21:59:48 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[OCaml]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[emacs]]></category>

		<category><![CDATA[tuareg]]></category>

		<category><![CDATA[yasnippet]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=21</guid>
		<description><![CDATA[Hi,
Some days ago, I found YASnippet.
I then started using it and extending it.
As I  currently develop mainly with OCaml (with tuareg-mode on Emacs), and that TABbing is much better (for me) than tuareg&#8217;s shortcut keys, I&#8217;ve created some snippets for tuareg-mode.
You can find them here : http://mestan.fr/ocaml/emacs/yasnippet-tuareg-mode.tar.gz
To install my snippets, assuming yasnippet is already [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,<br />
Some days ago, I found <a href="http://code.google.com/p/yasnippet/">YASnippet</a>.<br />
I then started using it and extending it.</p>
<p>As I  currently develop mainly with OCaml (with tuareg-mode on Emacs), and that TABbing is much better (for me) than tuareg&#8217;s shortcut keys, I&#8217;ve created some snippets for tuareg-mode.</p>
<p>You can find them here : <a href="http://mestan.fr/ocaml/emacs/yasnippet-tuareg-mode.tar.gz">http://mestan.fr/ocaml/emacs/yasnippet-tuareg-mode.tar.gz</a></p>
<p>To install my snippets, assuming yasnippet is already installed (otherwise, see <a href="http://code.google.com/p/yasnippet/">YASnippet&#8217;s page</a>), you have to :<br />
- Uncompress the tarball, getting a &#8220;tuareg-mode&#8221; folder;<br />
- Move it in <yasnippet directory>/snippets/text-mode/ (mine&#8217;s path is : ~/.emacs.d/plugins/yasnippet/snippets/text-mode/tuareg-mode/)<br />
- To get YASnippet work with tuareg-mode, you must add the following to your .emacs (or any init file loaded when emacs starts) BEFORE yasnippet&#8217;s loading code :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code31'); return false;">View Code</a> LISP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2131"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p21code31"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>add-hook 'tuareg-mode-hook
         '<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
            <span style="color: #66cc66;">&#40;</span>yas/minor-mode-on<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Then reload your .emacs or restart Emacs.</p>
<p>Now, when typing <em>leti</em> then TAB within tuareg-mode (e.g when editing a .ml file), it should expand to</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p21code32'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2132"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p21code32"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> <span style="color: #a52a2a;">|</span> <span style="color: #06c; font-weight: bold;">in</span></pre></td></tr></table></div>

<p>where | is emacs&#8217;s cursor.<br />
Note : typing TAB when cursor is between <em>let</em> and <em>in</em> moves the cursor at <em>in</em>&#8217;s right.</p>
<p>Here is the current snippet list I&#8217;ve defined :</p>
<ul>
<li><em>begin &#8230; end</em> => begin</li>
<li><em>module &#8230; = functor (&#8230;) -> struct &#8230; end</em> => functor</li>
<li><em>if &#8230; then &#8230; else &#8230;</em>=> if</li>
<li><em>let &#8230; in &#8230;</em> => leti</li>
<li><em>match &#8230; with &#8230; -> &#8230; | &#8230; -> &#8230;</em> => match</li>
<li><em>module &#8230; = struct &#8230; end</em> => module</li>
<li><em>module type &#8230; = sig &#8230; end</em> => sig</li>
<li><em>try &#8230; with</em> => try</li>
</ul>
<p>where the part on the left side of &#8220;=>&#8221; is obtained after having typed the part on the right side of &#8220;=>&#8221; then TAB.</p>
<p>Feel free to use and customize it, I&#8217;ll be glad to hear from you if you use it (by commenting this entry or at alp [AT] mestan [DOT] fr).</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/02/17/ocaml-completion-within-emacs-with-yasnippet-and-tuareg-mode/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
