<?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</title>
	<atom:link href="http://blog.mestan.fr/feed/" 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>3D Text Rendering in Haskell with FTGL</title>
		<link>http://blog.mestan.fr/2009/09/24/3d-text-rendering-in-haskell-with-ftgl/</link>
		<comments>http://blog.mestan.fr/2009/09/24/3d-text-rendering-in-haskell-with-ftgl/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 20:59:21 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[Haskell]]></category>

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

		<category><![CDATA[3D]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=38</guid>
		<description><![CDATA[Hi,
While I was writing a sort of password manager for my personal use (in Haskell) &#8212; actually, a friend of mine was doing the same in Java, so there was some competition  &#8212; I decided that just printing the password in the terminal wasn&#8217;t enough, at all. That&#8217;s why I decided to look at [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>While I was writing a sort of password manager for my personal use (in Haskell) &#8212; actually, a friend of mine was doing the same in Java, so there was some competition <img src='http://blog.mestan.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> &#8212; I decided that just printing the password in the terminal wasn&#8217;t enough, at all. That&#8217;s why I decided to look at how it was possible to render text easily inside an OpenGL context, with possibly some depth given to each letter.</p>
<p>You know what ? Nearly like every time you look for some library in Haskell, you find it ! Mine was <a href="http://hackage.haskell.org/package/FTGL">ftgl</a>. You can, with only few lines, while in an OpenGL context, create some 3D text from given text and (TrueType) font and render it.</p>
<p>Since it is really easy to get working, here&#8217;s a little howto.</p>
<p>- be sure to have libftgl (the C version of the library), glut (often <em>freeglut3</em> in distro repositories) and opengl correctly installed.<br />
- be sure to have the <a href="http://hackage.haskell.org/package/OpenGL-2.4.0.1">Haskell OpenGL binding</a> installed, and also <a href="http://hackage.haskell.org/package/GLUT">GLUT</a> (thus we can get a working 3D context in a (GLUT) window quite easily).<br />
- get the Haskell binding of FTGL from hackage using cabal : <em>cabal install ftgl</em>.</p>
<p>Then you can try to play around the following code, that you may want to compile with <em>ghc &#8211;make hs3dtext.hs -o hs3dtext</em>.</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('p38code2'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p382"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code" id="p38code2"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>List
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>IORef
<span style="color: #06c; font-weight: bold;">import</span> Graphics<span style="color: #339933; font-weight: bold;">.</span>Rendering<span style="color: #339933; font-weight: bold;">.</span>OpenGL
<span style="color: #06c; font-weight: bold;">import</span> Graphics<span style="color: #339933; font-weight: bold;">.</span>Rendering<span style="color: #339933; font-weight: bold;">.</span>FTGL
<span style="color: #06c; font-weight: bold;">import</span> Graphics<span style="color: #339933; font-weight: bold;">.</span>UI<span style="color: #339933; font-weight: bold;">.</span>GLUT
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
&nbsp;
main <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span> <span style="color: #339933; font-weight: bold;">_</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgsAndInitialize
  initialDisplayMode <span style="color: #339933; font-weight: bold;">$=</span> <span style="color: green;">&#91;</span>DoubleBuffered<span style="color: green;">&#93;</span>
  createWindow <span style="background-color: #3cb371;">&quot;3D Text Renderer&quot;</span>
  angle <span style="color: #339933; font-weight: bold;">&lt;-</span> newIORef <span style="color: red;">0.0</span>
  font <span style="color: #339933; font-weight: bold;">&lt;-</span> createExtrudeFont <span style="background-color: #3cb371;">&quot;FreeSans.ttf&quot;</span>
  setFontFaceSize font <span style="color: red;">7</span> <span style="color: red;">7</span>
  setFontDepth font <span style="color: red;">1.0</span>
  displayCallback <span style="color: #339933; font-weight: bold;">$=</span> display <span style="background-color: #3cb371;">&quot;Haskell&quot;</span> angle font
  idleCallback <span style="color: #339933; font-weight: bold;">$=</span> Just <span style="color: green;">&#40;</span>animate angle<span style="color: green;">&#41;</span>
  mainLoop
&nbsp;
display text angle font <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  clear <span style="color: green;">&#91;</span>ColorBuffer<span style="color: green;">&#93;</span>
  loadIdentity
  scale <span style="color: red;">0.04</span> <span style="color: red;">0.05</span> <span style="color: green;">&#40;</span><span style="color: red;">0.5</span> <span style="color: #339933; font-weight: bold;">::</span> GLfloat<span style="color: green;">&#41;</span>
  a <span style="color: #339933; font-weight: bold;">&lt;-</span> get angle
  rotate a <span style="color: #339933; font-weight: bold;">$</span> Vector3 <span style="color: red;">0</span> <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">::</span> GLfloat<span style="color: green;">&#41;</span>
  renderFont font text All
  swapBuffers
&nbsp;
animate angle <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  a <span style="color: #339933; font-weight: bold;">&lt;-</span> get angle
  <span style="color: #06c; font-weight: bold;">case</span> a <span style="color: #339933; font-weight: bold;">&gt;</span> <span style="color: red;">179</span> <span style="color: #06c; font-weight: bold;">of</span>
    True  <span style="color: #339933; font-weight: bold;">-&gt;</span> angle <span style="color: #339933; font-weight: bold;">$=</span> <span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">180</span>
    False <span style="color: #339933; font-weight: bold;">-&gt;</span> angle <span style="color: #339933; font-weight: bold;">$=</span> a <span style="color: #339933; font-weight: bold;">+</span> <span style="color: red;">0.03</span>
  postRedisplay Nothing</pre></td></tr></table></div>

<p>Don&#8217;t forget to get FreeSans.ttf from anywhere for it to work. The depth of the letters here is 1.0, you can play with it, but it doesn&#8217;t look as well as it does like I pasted.</p>
<p>Here is a cool screenshot <img src='http://blog.mestan.fr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
<center><img src="http://mestan.fr/pwd3.png" alt="Screen" /></center></p>
<p>Enjoy !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/09/24/3d-text-rendering-in-haskell-with-ftgl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C++ introspection library and portable industrial graphical components for GPL and commercial use</title>
		<link>http://blog.mestan.fr/2009/09/02/c-introspection-library-and-portable-industrial-graphical-components-for-gpl-and-commercial-use/</link>
		<comments>http://blog.mestan.fr/2009/09/02/c-introspection-library-and-portable-industrial-graphical-components-for-gpl-and-commercial-use/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 13:01:45 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[C++]]></category>

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

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

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

		<guid isPermaLink="false">http://blog.mestan.fr/?p=36</guid>
		<description><![CDATA[Hi,
I&#8217;ve just found out two libraries which seem to be very interesting.
The first, CAMP, is an introspection library for C++. It appears to be well-thought and easily usable in concrete projects. Indeed, it isn&#8217;t (at all !) intrusive, which means you don&#8217;t have to modify existing classes to expose them to introspection. The example given [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;ve just found out two libraries which seem to be very interesting.</p>
<p>The first, <a href="http://www.tegesoft.com/products/camp">CAMP</a>, is an introspection library for C++. It appears to be well-thought and easily usable in concrete projects. Indeed, it isn&#8217;t (at all !) intrusive, which means you don&#8217;t have to modify existing classes to expose them to introspection. The example given in the documentation will be better than my words to explain that :</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('p36code4'); return false;">View Code</a> CPP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p364"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
</pre></td><td class="code" id="p36code4"><pre class="cpp" style="font-family:monospace;"> <span style="color: #339900;">#include &lt;camp/camptype.hpp&gt;</span>
 <span style="color: #339900;">#include &lt;camp/class.hpp&gt;</span>
 <span style="color: #339900;">#include &lt;string&gt;</span>
 <span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
 <span style="color: #666666;">// Let's define a class for handling persons</span>
 <span style="color: #0000ff;">class</span> Person
 <span style="color: #008000;">&#123;</span>
 <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
&nbsp;
     <span style="color: #666666;">// Construct a person from its name</span>
     Person<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000040;">&amp;</span> name<span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> m_name<span style="color: #008000;">&#40;</span>name<span style="color: #008000;">&#41;</span>, m_age<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #666666;">// Retrieve the name of a person</span>
     std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
     <span style="color: #008000;">&#123;</span>
         <span style="color: #0000ff;">return</span> m_name<span style="color: #008080;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #666666;">// Retrieve the age of a person</span>
     <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> age<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
     <span style="color: #008000;">&#123;</span>
         <span style="color: #0000ff;">return</span> m_age<span style="color: #008080;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #666666;">// Set the age of a person</span>
     <span style="color: #0000ff;">void</span> setAge<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> age<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
         m_age <span style="color: #000080;">=</span> age<span style="color: #008080;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
     <span style="color: #666666;">// Make a person speak (tell about its name and age)</span>
     <span style="color: #0000ff;">void</span> speak<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
     <span style="color: #008000;">&#123;</span>
         std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Hi! My name is &quot;</span> <span style="color: #000080;">&lt;&lt;</span> m_name <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; and I'm &quot;</span> <span style="color: #000080;">&lt;&lt;</span> m_age <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; years old.&quot;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
     <span style="color: #008000;">&#125;</span>
&nbsp;
 <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
&nbsp;
     std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> m_name<span style="color: #008080;">;</span>
     <span style="color: #0000ff;">unsigned</span> <span style="color: #0000ff;">int</span> m_age<span style="color: #008080;">;</span>
 <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
 <span style="color: #666666;">// Make the Person type available to CAMP</span>
 CAMP_TYPE<span style="color: #008000;">&#40;</span>Person<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
&nbsp;
 <span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
 <span style="color: #008000;">&#123;</span>
     <span style="color: #666666;">// Bind our Person class to CAMP</span>
     camp<span style="color: #008080;">::</span><span style="color: #0000ff;">Class</span><span style="color: #008080;">::</span><span style="color: #007788;">declare</span><span style="color: #000080;">&lt;</span>Person<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Person&quot;</span><span style="color: #008000;">&#41;</span>
         .<span style="color: #007788;">constructor1</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
         .<span style="color: #007788;">property</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;name&quot;</span>, <span style="color: #000040;">&amp;</span>Person<span style="color: #008080;">::</span><span style="color: #007788;">name</span><span style="color: #008000;">&#41;</span>
         .<span style="color: #007788;">property</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;age&quot;</span>, <span style="color: #000040;">&amp;</span>Person<span style="color: #008080;">::</span><span style="color: #007788;">age</span>, <span style="color: #000040;">&amp;</span>Person<span style="color: #008080;">::</span><span style="color: #007788;">setAge</span><span style="color: #008000;">&#41;</span>
         .<span style="color: #007788;">function</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;speak&quot;</span>, <span style="color: #000040;">&amp;</span>Person<span style="color: #008080;">::</span><span style="color: #007788;">speak</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Retrieve it by its name</span>
     <span style="color: #0000ff;">const</span> camp<span style="color: #008080;">::</span><span style="color: #0000ff;">Class</span><span style="color: #000040;">&amp;</span> metaclass <span style="color: #000080;">=</span> camp<span style="color: #008080;">::</span><span style="color: #007788;">classByName</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Person&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Construct a new person named John</span>
     Person<span style="color: #000040;">*</span> john <span style="color: #000080;">=</span> metaclass.<span style="color: #007788;">construct</span><span style="color: #000080;">&lt;</span>Person<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>camp<span style="color: #008080;">::</span><span style="color: #007788;">Args</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;John&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Print its name</span>
     std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> name <span style="color: #000080;">=</span> metaclass.<span style="color: #007788;">property</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;name&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span>john<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
     std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;John's name is: &quot;</span> <span style="color: #000080;">&lt;&lt;</span> name <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Set its age to 24</span>
     metaclass.<span style="color: #007788;">property</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;age&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">set</span><span style="color: #008000;">&#40;</span>john, <span style="color: #0000dd;">24</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Make John say something</span>
     metaclass.<span style="color: #007788;">function</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;speak&quot;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">call</span><span style="color: #008000;">&#40;</span>john<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #666666;">// Kill John</span>
     metaclass.<span style="color: #007788;">destroy</span><span style="color: #008000;">&#40;</span>john<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
 <span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>The key part here is <em>CAMP_TYPE(your_class)</em>. It exposes <em>your_class</em> to the introspection engine. Then, you bind anything you want from your class to the introspection engine, and you can play with all the CAMP API.</p>
<p>There&#8217;s also <a href="http://www.tegesoft.com/products/gics">GICS</a>, a portable library of industrial graphical components. Here are some screenshots :<br />
<img src="http://www.tegesoft.com/var/ezwebin_site/storage/images/tegesoft_com/products/gics/gauge_skin_example/4524-1-eng-GB/gauge_skin_example_gallerythumbnail.png" alt="Gauge" /><br />
<img src="http://www.tegesoft.com/var/ezwebin_site/storage/images/tegesoft_com/products/gics/gics_demo/4520-1-eng-GB/gics_demo_gallerythumbnail.png" alt="More complete example" /><br />
Since it is based on Qt 4.5 and its QGraphicsView module, it is very efficient, scalable and easy to use. One can rely on that since Qt&#8217;s popularity and use is increasing, day after day.</p>
<p>Both are double-licensed : GPL and Commercial, depending on your usage. More informations and download links can be found on the products page of Tegesoft : http://www.tegesoft.com/products</p>
<p>I&#8217;m happy to see such good libraries, written in good C++, available under GPL !</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/09/02/c-introspection-library-and-portable-industrial-graphical-components-for-gpl-and-commercial-use/feed/</wfw:commentRss>
		</item>
		<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('p30code6'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p306"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p30code6"><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('p28code8'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p288"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p28code8"><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('p26code12'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2612"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p26code12"><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('p26code13'); return false;">View Code</a> LAMBDA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2613"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p26code13"><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('p26code14'); return false;">View Code</a> LAMBDA</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2614"><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="p26code14"><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('p25code16'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p2516"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p25code16"><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>Writing powerful concurrent video-games with ACCLib in C++</title>
		<link>http://blog.mestan.fr/2009/02/26/writing-powerful-concurrent-video-games-with-acclib-in-c/</link>
		<comments>http://blog.mestan.fr/2009/02/26/writing-powerful-concurrent-video-games-with-acclib-in-c/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 07:06:24 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
		
		<category><![CDATA[C++]]></category>

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

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

		<category><![CDATA[video-games]]></category>

		<guid isPermaLink="false">http://blog.mestan.fr/?p=24</guid>
		<description><![CDATA[I&#8217;ve been recently involve in an amazing project, the first multithreaded game engine with real performance on multicore processors.
We are all aware of the lack of video game performance on multicore, this engine claim linear performance scaling on manycore processors.
About x4 performance gain on a quadcore HT corei7 (see here) . Independent results with cinebench [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been recently involve in an amazing project, the first multithreaded game engine with real performance on multicore processors.<br />
We are all aware of the lack of video game performance on multicore, this engine claim linear performance scaling on manycore processors.<br />
About x4 performance gain on a quadcore HT corei7 (<a href="http://www.acclib.com/2009/01/load-balancing-corei7-27012009.html">see here</a>) . Independent results with cinebench and PovRay show amost the same results (4.38 at best). That means one thing : ACCLib is a great product, their video game demo shows the same performance results of easy to parallel applications. Free lunch is not over for video game.</p>
<p><img src="http://mestan.fr/bench.jpg" alt="Benchmark" /></p>
<p>I highly recommend to visit this site : <a href="http://www.acclib.com/">ACCLib.com</a> to get more informations.</p>

]]></content:encoded>
			<wfw:commentRss>http://blog.mestan.fr/2009/02/26/writing-powerful-concurrent-video-games-with-acclib-in-c/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
