<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coder-Studio &#187; ocaml</title>
	<atom:link href="http://www.coder-studio.com/blog/tag/ocaml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coder-studio.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 02 Mar 2011 22:17:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>OCaml et la 3D : CamlGL &amp; LablGL</title>
		<link>http://www.coder-studio.com/blog/276/</link>
		<comments>http://www.coder-studio.com/blog/276/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 15:50:35 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[GlCaml]]></category>
		<category><![CDATA[LablGl]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[ocamlsdl]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[SDL]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=276</guid>
		<description><![CDATA[Bonsoir, Comme demandé récemment par l'un des membres, il est tout à fait possible de faire de la 3D avec OpenGL en OCaml. Il y a principalement 2 bindings. LablGL GlCaml Inutile de commencer à donner un cours sur OpenGL, la plupart d'entre vous connaissant déjà, qui plus est il y a tout le nécessaire [...]]]></description>
			<content:encoded><![CDATA[<p>Bonsoir,</p>
<p>Comme demandé récemment par l'un des membres, il est tout à fait possible de faire de la 3D avec OpenGL en OCaml. Il y a principalement 2 bindings.</p>
<ul>
<li><a href="http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/lablgl.html">LablGL</a></li>
<li><a href="http://glcaml.sourceforge.net/">GlCaml</a></li>
</ul>
<p><div id="attachment_277" class="wp-caption aligncenter" style="width: 657px"><a href="http://www.coder-studio.com/blog/wp-content/uploads/2009/04/glcaml.png"><img src="http://www.coder-studio.com/blog/wp-content/uploads/2009/04/glcaml.png" alt="Exemple d&#039;utilisation de GlCaml" title="glcaml" width="647" height="517" class="size-full wp-image-277" /></a><p class="wp-caption-text">Exemple d'utilisation de GlCaml</p></div><br />
Inutile de commencer à donner un cours sur OpenGL, la plupart d'entre vous connaissant déjà, qui plus est il y a tout le nécessaire pour OpenGL en C &#038; C++. Ces deux bibliothèques OCaml ne sont que des bindings, c'est à dire qu'elles appellent les fonctions C classiques en interfaçant par le biais de fonctions OCaml.</p>
<p>Juste pour vous donner une idée, voici un extrait du code correspondant au screenshot ci-dessus. Il s'agissait ici de montrer que ça existe, à quoi ça ressemble et où trouver le nécessaire pour s'y mettre.</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('p276code2'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2762"><td class="code" id="p276code2"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> draw_gl_scene <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
    glClear  <span style="color: #6c6;">&#40;</span>gl_color_buffer_bit lor gl_depth_buffer_bit<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>		 <span style="color: #5d478b; font-style: italic;">(* Clear The Screen And The Depth Buffer *)</span>
    glLoadIdentity  <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>				 <span style="color: #5d478b; font-style: italic;">(* Reset The View*)</span>
&nbsp;
    glTranslatef <span style="color: #c6c;">0.0</span> <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">!</span>z <span style="color: #a52a2a;">;</span>                   <span style="color: #5d478b; font-style: italic;">(* move z units out from the screen. *)</span>
&nbsp;
    glRotatef <span style="color: #a52a2a;">!</span>xrot <span style="color: #c6c;">1.0</span> <span style="color: #c6c;">0.0</span> <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>		 <span style="color: #5d478b; font-style: italic;">(* Rotate On The X Axis *)</span>
    glRotatef <span style="color: #a52a2a;">!</span>yrot <span style="color: #c6c;">0.0</span> <span style="color: #c6c;">1.0</span> <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>		 <span style="color: #5d478b; font-style: italic;">(* Rotate On The Y Axis *)</span>
&nbsp;
    glBindTexture gl_texture_2d  texture<span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">!</span>filter<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>    <span style="color: #5d478b; font-style: italic;">(* choose the texture to use. *)</span>
&nbsp;
    glBegin gl_quads <span style="color: #a52a2a;">;</span>		                 <span style="color: #5d478b; font-style: italic;">(* begin drawing a cube *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Front Face  note that the texture's corners have to match the quad's corners  *)</span>
    glNormal3f  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>                               <span style="color: #5d478b; font-style: italic;">(* front face points out of the screen on z. *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Back Face *)</span>
    glNormal3f  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>                               <span style="color: #5d478b; font-style: italic;">(* back face points into the screen on z. *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Top Face *)</span>
    glNormal3f  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>                               <span style="color: #5d478b; font-style: italic;">(* top face points up on y. *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Bottom Face   *)</span>     
    glNormal3f  <span style="color: #c6c;">0.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>                              <span style="color: #5d478b; font-style: italic;">(* bottom face points down on y.  *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Right face *)</span>
    glNormal3f  <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>                               <span style="color: #5d478b; font-style: italic;">(* right face points right on x. *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f  <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
&nbsp;
     <span style="color: #5d478b; font-style: italic;">(* Left Face *)</span>
    glNormal3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span>                               <span style="color: #5d478b; font-style: italic;">(* left face points left on x. *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Left Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">0.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Bottom Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">1.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>   <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Right Of The Texture and Quad *)</span>
    glTexCoord2f <span style="color: #c6c;">0.0</span>  <span style="color: #c6c;">1.0</span> <span style="color: #a52a2a;">;</span> glVertex3f <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span>   <span style="color: #c6c;">1.0</span>  <span style="color: #6c6;">&#40;</span><span style="color: #a52a2a;">-.</span>1<span style="color: #a52a2a;">.</span>0<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">;</span>	 <span style="color: #5d478b; font-style: italic;">(* Top Left Of The Texture and Quad *)</span>
&nbsp;
    glEnd  <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span><span style="color: #a52a2a;">;</span>                                     <span style="color: #5d478b; font-style: italic;">(* done with the polygon. *)</span>
&nbsp;
    xrot <span style="color: #a52a2a;">:=</span> <span style="color: #a52a2a;">!</span>xrot <span style="color: #a52a2a;">+.</span> <span style="color: #a52a2a;">!</span>xspeed<span style="color: #a52a2a;">;</span>		                 <span style="color: #5d478b; font-style: italic;">(* X Axis Rotation	 *)</span>
    yrot <span style="color: #a52a2a;">:=</span> <span style="color: #a52a2a;">!</span>yrot <span style="color: #a52a2a;">+.</span> <span style="color: #a52a2a;">!</span>yspeed		                 <span style="color: #5d478b; font-style: italic;">(* Y Axis Rotation *)</span></pre></td></tr></table></div>

<p>PS : aucun des deux ne semble être encore maintenu, toutefois GlCaml prend en charge les versions d'OpenGL jusqu'à 2.1 + extensions ARB et spécifiques aux vendeurs. GlCaml embarque un binding minimal de la SDL, moins complet que OCamlSDL que j'ai présenté dans un post précédent.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/276/feed/</wfw:commentRss>
		<slash:comments>5107</slash:comments>
		</item>
		<item>
		<title>Bouncing Ball en OCaml avec OCamlSDL</title>
		<link>http://www.coder-studio.com/blog/bouncing-ball-en-ocaml-avec-ocamlsdl/</link>
		<comments>http://www.coder-studio.com/blog/bouncing-ball-en-ocaml-avec-ocamlsdl/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 23:26:17 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[2D]]></category>
		<category><![CDATA[bouncing ball]]></category>
		<category><![CDATA[fonctionnel]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[ocamlsdl]]></category>
		<category><![CDATA[programmation fonctionnelle]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=271</guid>
		<description><![CDATA[Bonsoir, J'ai écrit un petit programme OCaml de Boucing Ball, une balle qui rebondit contre les bords de la fenêtre, où l'on peut augmenter la vitesse en X et en Y avec les touches du clavier. Il utilise OCamlSDL, un binding de la désormais célèbre bibliothèque SDL pour le langage OCaml. Voici ce que cela [...]]]></description>
			<content:encoded><![CDATA[<p>Bonsoir,</p>
<p>J'ai écrit un petit programme OCaml de Boucing Ball, une balle qui rebondit contre les bords de la fenêtre, où l'on peut augmenter la vitesse en X et en Y avec les touches du clavier.<br />
Il utilise OCamlSDL, un binding de la désormais célèbre bibliothèque <a href="http://www.libsdl.org/">SDL</a> pour le langage OCaml.</p>
<p>Voici ce que cela donne.</p>
<p><center><div id="attachment_272" class="wp-caption alignnone" style="width: 410px"><a href="http://www.coder-studio.com/blog/wp-content/uploads/2009/04/bbsdl.png"><img src="http://www.coder-studio.com/blog/wp-content/uploads/2009/04/bbsdl.png" alt="Boucing Ball en action" title="bbsdl" width="400" height="316" class="size-full wp-image-272" /></a><p class="wp-caption-text">Boucing Ball en action</p></div></center></p>
<p>Si vous voulez tester et/ou améliorer ce programme, qui peut soit dit en passant servir de base pour un Pong ou autre jeu de ce genre, vous trouverez le code source ici : <a href="http://mestan.fr/ocaml/bbsdl/bbsdl.tar.gz">bbsdl.tar.gz</a>.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/bouncing-ball-en-ocaml-avec-ocamlsdl/feed/</wfw:commentRss>
		<slash:comments>2039</slash:comments>
		</item>
		<item>
		<title>La programmation fonctionnelle n&#039;est pas un jouet pour académiciens</title>
		<link>http://www.coder-studio.com/blog/la-programmation-fonctionnelle-nest-pas-un-jouet-pour-academiciens/</link>
		<comments>http://www.coder-studio.com/blog/la-programmation-fonctionnelle-nest-pas-un-jouet-pour-academiciens/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 18:30:26 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[programmation fonctionnelle]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=267</guid>
		<description><![CDATA[Bonjour, Cela fait maintenant un moment que j'apprends et pratique la programmation fonctionnelle, aussi bien sur le point de vue théorique en m'intéressant à ses relations avec la théorie des catégories (mathématiques) entre autres, que sur le point de vue pratique, c'est à dire que j'ai mené quelques projets (de petite envergure... oui, c'est proportionnel [...]]]></description>
			<content:encoded><![CDATA[<p>Bonjour,</p>
<p>Cela fait maintenant un moment que j'apprends et pratique la programmation fonctionnelle, aussi bien sur le point de vue théorique en m'intéressant à ses relations avec la théorie des catégories (mathématiques) entre autres, que sur le point de vue pratique, c'est à dire que j'ai mené quelques projets (de petite envergure... oui, c'est proportionnel au temps que je peux passer dessus) à bien.</p>
<p>Quand on dit "langage fonctionnel" ou "programmation fonctionnelle", les gens s'imaginent (pour ceux qui ne connaissent pas) des programmes avec tout un tas de fonctions, c'est tout. Ce n'est pas ça la programmation fonctionnelle. Enfin biensûr il y a des fonctions, mais la programmation fonctionnelle ne s'arrête pas là.</p>
<p>Déjà, la programmation fonctionnelle, c'est une toute autre façon de concevoir des programmes. Détailler toutes les différences avec la programmation impérative serait pire que les 12 travaux d'Hercules et c'est pourquoi je ne le ferai pas. Je vais toutefois vous parler des points qui font que je suis désormais adepte de ce style de programmation.</p>
<p><center><img src="http://www.geocities.com/EnchantedForest/1110/images/lambda.gif" alt="" title="La programmation fonctionnelle tire ses racines du lambda-calcul" /></center><br />
<span id="more-267"></span></p>
<p>Tout d'abord, étant assez orienté mathématiques, il y a une première chose qui me plaît. Dans les langages de programmation fonctionnelle (du moins la plupart), on définit des types, des opérations sur ces types, le tout très simplement et de manière on ne peut plus cohérente.</p>
<p>Ensuite, pour les langages fonctionnels compilés et typés statiquement, on est généralement accompagné d'un compilateur très strict, qui tentera d'éliminer un maximum d'incohérences (comprendre "erreurs") en nous envoyant des erreurs très précises en rapport avec le fait que nous n'avons pas bien typé des parties de notre programme. De plus, les 3 langages majeurs pour une utilisation "real world", Haskell, OCaml et F#, ont vu leur compilateur se doter de l'inférence de type ; il s'agit de la capacité qu'a un compilateur a donner lui-même un type à vos valeurs dans le programme (fonctions, expressions, ...). Entre ceci et la vérification des types, la compilation possède une part de travail autour des types en action dans votre code.</p>
<p>De plus, en programmation fonctionnelle, il s'agit de ne pas avoir ce que l'on appelle des effets de bords ; on parle de programmation fonctionnelle pure ; dans un tel cadre, une fonction à qui l'on donne les mêmes entrées renverra toujours la même sortie. Les programmeurs fonctionnels font en sorte d'isoler les parties pour lesquelles ce n'est pas vrai (lecture d'un fichier, intéraction réseau, ...) : monades en Haskell, on laisse la possibilité de faire de l'impératif pour OCaml et F#, ... </p>
<p>Continuons sur la curryfication. Cette dernière consiste à faire par exemple d'une fonction de 2 arguments 2 fonctions à 1 argument, qui pourront s'appliquer partiellement. Si l'on définit une fonction "add" pour ajouter 2 nombres x et y, alors on pourra appliquer add à son premier argument, x, en lui donnant par exemple la valeur 12, pour obtenir une fonction à UN SEUL argument qui additionnera son argument à 12.</p>
<p>Les fonctions sont capitales en programmation fonctionnelle. Contrairement à dans un certain nombre de langages (beaucoup), les fonctions peuvent être stockées, passées en argument, construites à la volée, retournées par d'autres fonctions, etc. Elles deviennent des valeurs de première classe. </p>
<p>A propos du passage en argument, une chose très importante en programmation fonctionnelle est la possibilité d'abstraire une partie des algorithmes et d'en confier la responsabilité à une fonction donnée en argument par exemple. Une fonction qui prend une autre fonction en argument est appelée "fonction d'ordre supérieur". Cela permet de factoriser un maximum de code tout en laissant la variabilité possible grâce au passage de fonction en argument. Le compilateur fera les vérifications nécessaires pour voir si les types concordent, ne vous inquiétez pas.</p>
<p>La paresse est également quelque chose qui s'avère bien sympathique parfois. Il s'agit de n'évaluer une expression qu'au moment où l'on en aura besoin (affichage du résultat de l'évaluation de l'expression -- comme une addition -- par exemple). Elle est mise en oeuvre différemment selon les langages (implicitement en Haskell, c'est le compilateur qui gère cela, alors que c'est explicit en OCaml -- module Lazy).</p>
<p>Tout cela, rajouté aux syntaxes assez simples, donne une très grande expressivité aux langages fonctionnels, proche de l'expressivité que l'on a en mathématiques. Qui plus est, rappelons-le, les langages fonctionnels sont des langages dits "déclaratifs". On exprime le problème, on obtient la solution, contrairement à ce que l'on fait dans un langage impératif où l'on doit donner toutes les étapes à la main nous-mêmes.</p>
<p>Bref, beaucoup d'avantages, un tout nouveau style de programmation, cela ne vaut-il pas le détour ? Allez, si vous voulez en savoir plus, voici quelques liens essentiels pour terminer ce billet sur la programmation fonctionnelle.<br />
<a href="http://damien-guichard.developpez.com/tutoriels/ocaml/">Cours d'introduction à OCaml de Damien Guichard</a> -- dont je me suis beaucoup servi et que j'apprécie beaucoup<br />
<a href="http://gorgonite.developpez.com/livres/traductions/haskell/gentle-haskell/">Traduction de "A gentle introduction to Haskell"</a> -- un peu rude pour débuter, mais vous fera comprendre pas mal de choses. </p>
<p>N'hésitez pas à utiliser le forum pour donner vos avis et retours d'expérience ou pour des questions, bien évidemment !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/la-programmation-fonctionnelle-nest-pas-un-jouet-pour-academiciens/feed/</wfw:commentRss>
		<slash:comments>1026</slash:comments>
		</item>
		<item>
		<title>Les sujets en rapport avec OCaml qui vous intéresseraient</title>
		<link>http://www.coder-studio.com/blog/les-sujets-en-rapport-avec-ocaml-qui-vous-interesseraient/</link>
		<comments>http://www.coder-studio.com/blog/les-sujets-en-rapport-avec-ocaml-qui-vous-interesseraient/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 18:18:18 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=262</guid>
		<description><![CDATA[Salut, Étant tombé amoureux du langage OCaml, et comptant propulser cette activité de blog sur Coder-Studio, j'aimerais savoir ce que vous, amateur du langage OCaml, de la programmation fonctionnelle en général ou tout simplement curieux, vous souhaiteriez lire en rapport avec OCaml sur notre site préféré Alors ? Quelques grandes lignes qui pourraient intéresser : [...]]]></description>
			<content:encoded><![CDATA[<p><center>Salut,</center></p>
<p><center><img src="http://lampwww.epfl.ch/%7Emichelou/images/ocaml.gif" alt="" /></center></p>
<p>Étant tombé amoureux du langage OCaml, et comptant propulser cette activité de blog sur Coder-Studio, j'aimerais savoir ce que vous, amateur du langage OCaml, de la programmation fonctionnelle en général ou tout simplement curieux, vous souhaiteriez lire en rapport avec OCaml sur notre site préféré <img src='http://www.coder-studio.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Alors ?<br />
Quelques grandes lignes qui pourraient intéresser :<br />
- OCaml et les maths (comme <a href="http://www.coder-studio.com/blog/construction-de-lensemble-de-cantor-en-ocaml/">mon billet précédent</a>)<br />
- OCaml et les GUIs<br />
- OCaml et le multimédia (OCamlSDL, OCaml/OpenGL, ...)<br />
- OCaml et la conception de compilateurs/interpréteurs (lexing, parsing, etc)<br />
- ...</p>
<p>Merci de donner votre avis !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/les-sujets-en-rapport-avec-ocaml-qui-vous-interesseraient/feed/</wfw:commentRss>
		<slash:comments>1759</slash:comments>
		</item>
		<item>
		<title>Construction de l&#039;Ensemble de Cantor en OCaml</title>
		<link>http://www.coder-studio.com/blog/construction-de-lensemble-de-cantor-en-ocaml/</link>
		<comments>http://www.coder-studio.com/blog/construction-de-lensemble-de-cantor-en-ocaml/#comments</comments>
		<pubDate>Sat, 18 Apr 2009 23:12:36 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[batteries]]></category>
		<category><![CDATA[cantor]]></category>
		<category><![CDATA[included]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[ocaml]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=235</guid>
		<description><![CDATA[Bonsoir, Un billet à propos d'OCaml, encore. Je me suis amusé à implémenter la construction de l'Ensemble de Cantor (version anglaise un peu plus complète). Vous voulez en savoir plus ? Première étape, il me fallait une fonction qui à partir d'une liste et d'un couple (a,b) de nombre réels, représentant l'intervalle [a,b], rajoute les [...]]]></description>
			<content:encoded><![CDATA[<p>Bonsoir,</p>
<p>Un billet à propos d'OCaml, encore. Je me suis amusé à implémenter la construction de <a href="http://fr.wikipedia.org/wiki/Ensemble_de_Cantor">l'Ensemble de Cantor</a> (<a href="http://en.wikipedia.org/wiki/Cantor_set">version anglaise un peu plus complète</a>). Vous voulez en savoir plus ?</p>
<p><center><a href="http://www.coder-studio.com/blog/construction-de-lensemble-de-cantor-en-ocaml/#more-235"><img src="http://www.developpez.net/forums/u67052-a100-i323.png" alt="Construction de l'Ensemble de Cantor" /></a><br />
<span id="more-235"></span></center></p>
<p>Première étape, il me fallait une fonction qui à partir d'une liste et d'un couple (a,b) de nombre réels, représentant l'intervalle [a,b], rajoute les deux intervalles qui en sont générés par une itéraction de la construction de l'ensemble de Cantor, c'est à dire les intervalles [a, (2a+b)/3] et [(a+2b)/3, b], à la liste. Voici la fonction en question, appelée cantor_step ici :</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('p235code9'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2359"><td class="code" id="p235code9"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> cantor_step l <span style="color: #6c6;">&#40;</span>a,b<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span>
 <span style="color: #6c6;">&#40;</span>a, <span style="color: #6c6;">&#40;</span>a <span style="color: #a52a2a;">+.</span> <span style="color: #060;">a</span> <span style="color: #a52a2a;">+.</span> <span style="color: #060;">b</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/.</span> <span style="color: #c6c;">3</span><span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">::</span> <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#40;</span>a <span style="color: #a52a2a;">+.</span> <span style="color: #060;">b</span> <span style="color: #a52a2a;">+.</span> <span style="color: #060;">b</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">/.</span> <span style="color: #c6c;">3</span><span style="color: #a52a2a;">.</span>, b<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">::</span> l</pre></td></tr></table></div>

<p>Ensuite, il fallait une fonction qui permettre d'appliquer cette fonction sur une liste de couples (a,b) pour passer d'une liste d'intervalles à une autre, c'est à dire passer à l'étape suivante de la génération de l'Ensemble de Cantor. J'ai par la même occasion profité pour rajouté un paramètre n permettant de réaliser cela n fois. J'ai appelé cette fonction map_n.</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('p235code10'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23510"><td class="code" id="p235code10"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> map_n f l n <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">match</span> l <span style="color: #06c; font-weight: bold;">with</span>
  <span style="color: #a52a2a;">|</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span>
  <span style="color: #a52a2a;">|</span> l <span style="color: #a52a2a;">-&gt;</span> aux l n 
      where
	<span style="color: #06c; font-weight: bold;">rec</span> aux l <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">function</span> 
	  <span style="color: #a52a2a;">|</span> <span style="color: #c6c;">0</span> <span style="color: #a52a2a;">-&gt;</span> l
	  <span style="color: #a52a2a;">|</span> k <span style="color: #a52a2a;">-&gt;</span> aux <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="color: #06c; font-weight: bold;">List</span></a><span style="color: #a52a2a;">.</span><span style="color: #060;">fold_left</span> f <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span> l<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>k<span style="color: #a52a2a;">-</span><span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<p>List.fold_left est ce que l'on appelle un "pliage" (<em>fold</em> en Anglais). Pour vous familiariser avec ces derniers, une recherche sur "functional programming fold" devrait vous apporter le nécessaire <img src='http://www.coder-studio.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ). Il permet de parcourir la liste d'une certaine façon en appliquant une certaine fonction sur l'élément courant et le résultat de ce qui a été fait jusque là de la même façon, et ainsi de suite. </p>
<p>Enfin, définissons une fonction nth_cantor qui permet d'obtenir la liste des intervalles qui constituent la n-ème itéraction de la construction de l'Ensemble de Cantor.</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('p235code11'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23511"><td class="code" id="p235code11"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> nth_cantor <span style="color: #a52a2a;">=</span> <span style="color: #06c; font-weight: bold;">function</span>
  <span style="color: #a52a2a;">|</span> <span style="color: #c6c;">0</span> <span style="color: #a52a2a;">-&gt;</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#40;</span><span style="color: #c6c;">0</span><span style="color: #a52a2a;">.</span>,<span style="color: #c6c;">1</span><span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#93;</span>
  <span style="color: #a52a2a;">|</span> k <span style="color: #a52a2a;">-&gt;</span> map_n cantor_step <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#40;</span><span style="color: #c6c;">0</span><span style="color: #a52a2a;">.</span>,<span style="color: #c6c;">1</span><span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#41;</span><span style="color: #6c6;">&#93;</span> k</pre></td></tr></table></div>

<p>On voit donc que l'on part de l'intervalle [0,1], et que l'on va répéter k fois l'itéraction. </p>
<p>Deux fonctions utilitaires, dont une qui utilise non pas le module List standard mais le module List de OCaml Batteries Included, pour la fonction print. (en fait, List.fold_left ci-dessus est également celui de OCaml Batteries Included, étant donné que le programme sera compilé avec OCaml Batteries Included).</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('p235code12'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23512"><td class="code" id="p235code12"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> couple_printer <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALoutput"><span style="color: #06c; font-weight: bold;">output</span></a> <span style="color: #6c6;">&#40;</span>a,b<span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html"><span style="color: #06c; font-weight: bold;">Printf</span></a><span style="color: #a52a2a;">.</span><span style="color: #060;">printf</span> <span style="color: #3cb371;">&quot;(%f,%f)\n&quot;</span> a b
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> list_printer l <span style="color: #a52a2a;">=</span>  <span style="color: #5d478b; font-style: italic;">(* List.print couple_printer stdout l ;*)</span>  <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Printf.html"><span style="color: #06c; font-weight: bold;">Printf</span></a><span style="color: #a52a2a;">.</span><span style="color: #060;">printf</span> <span style="color: #3cb371;">&quot;\n%d intervals in list\n&quot;</span> <span style="color: #6c6;">&#40;</span><a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/List.html"><span style="color: #06c; font-weight: bold;">List</span></a><span style="color: #a52a2a;">.</span><span style="color: #060;">length</span> l<span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<p>La première permet d'afficher un couple de réels depuis ... un couple de réels.<br />
La seconde permet d'afficher une liste en précisant quelle fonction utiliser pour afficher chaque élément. Elle affiche ensuite la taille. Ici, le passage d'affichage des éléments est commenté (entre (* ... *)) car ayant testé mon code avec notamment 25 itérations, on se retrouve avec beaucoup trop de choses à afficher pour que ça soit supportable pour un être humain normal.</p>
<p>Enfin, le code qui est exécuté :</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('p235code13'); return false;">View Code</a> OCAML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23513"><td class="code" id="p235code13"><pre class="ocaml" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> main <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span> <span style="color: #a52a2a;">=</span> 
  <span style="color: #06c; font-weight: bold;">try</span> 
    <span style="color: #06c; font-weight: bold;">let</span> n <span style="color: #a52a2a;">=</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALint_of_string"><span style="color: #06c; font-weight: bold;">int_of_string</span></a> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Sys.html"><span style="color: #06c; font-weight: bold;">Sys</span></a><span style="color: #a52a2a;">.</span><span style="color: #060;">argv</span><span style="color: #a52a2a;">.</span><span style="color: #6c6;">&#40;</span><span style="color: #c6c;">1</span><span style="color: #6c6;">&#41;</span> <span style="color: #06c; font-weight: bold;">in</span>
    <span style="color: #06c; font-weight: bold;">let</span> cn <span style="color: #a52a2a;">=</span> nth_cantor n <span style="color: #06c; font-weight: bold;">in</span>
      list_printer cn
  <span style="color: #06c; font-weight: bold;">with</span> _ <span style="color: #a52a2a;">-&gt;</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALprint_endline"><span style="color: #06c; font-weight: bold;">print_endline</span></a> <span style="color: #3cb371;">&quot;Use : ./cantor n, where n is an integer&quot;</span> <span style="color: #a52a2a;">;</span> <a href="http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html#VALexit"><span style="color: #06c; font-weight: bold;">exit</span></a> <span style="color: #c6c;">0</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> _ <span style="color: #a52a2a;">=</span> main <span style="color: #6c6;">&#40;</span><span style="color: #6c6;">&#41;</span></pre></td></tr></table></div>

<p>Pour  terminer, la compilation :</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('p235code14'); return false;">View Code</a> SHELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p23514"><td class="code" id="p235code14"><pre class="shell" style="font-family:monospace;">$ ocamlfind batteries/ocamlopt -o cantor cantor.ml</pre></td></tr></table></div>

<p>(pas d'optimisation ici, si vous les voulez, rajouter -cc -O<em>n</em> après ocamlopt)</p>
<p>Et on exécute :</p>
<blockquote><p>$ time ./cantor 25<br />
33554432 intervals in list</p>
<p>real    0m25.553s<br />
user    0m23.481s<br />
sys     0m2.060s
</p></blockquote>
<p>En activant l'affichage des éléments, sur un petit nombre d'itérations :</p>
<blockquote><p>$ time ./cantor 4<br />
[(0.740741,0.753086)<br />
; (0.765432,0.777778)<br />
; (0.666667,0.679012)<br />
; (0.691358,0.703704)<br />
; (0.962963,0.975309)<br />
; (0.987654,1.000000)<br />
; (0.888889,0.901235)<br />
; (0.913580,0.925926)<br />
; (0.074074,0.086420)<br />
; (0.098765,0.111111)<br />
; (0.000000,0.012346)<br />
; (0.024691,0.037037)<br />
; (0.296296,0.308642)<br />
; (0.320988,0.333333)<br />
; (0.222222,0.234568)<br />
; (0.246914,0.259259)<br />
]<br />
16 intervals in list</p>
<p>real    0m0.013s<br />
user    0m0.000s<br />
sys     0m0.016s
</p></blockquote>
<p>Vous avez surement remarqué que cette méthode ne préserve pas l'ordre des intervalles... Ce n'a pas vraiment été mon soucis premier, et ce serait arrangé avec la méthode décrite ci-dessous.</p>
<p>Au passage, si j'utilisais des arbres binaires pour toutes les étapes intermédiaires et que je produisais une liste depuis cet arbre, je gagnerais pas mal en efficacité, disons que je vous le laisse à titre d'exercice <img src='http://www.coder-studio.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Enjoy !</p>
<p>PS : la capture d'écran ci-dessus provient d'un programme que j'avais réalisé il y a quelques mois et qui faisait une construction itérative représentée graphiquement, mais la méthode de génération était moins efficace, et j'ai la flemme de refaire la même chose maintenant...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/construction-de-lensemble-de-cantor-en-ocaml/feed/</wfw:commentRss>
		<slash:comments>1382</slash:comments>
		</item>
		<item>
		<title>OCaml Batteries Included : un effort pour fournir une bibliothèque standard digne de ce nom pour OCaml</title>
		<link>http://www.coder-studio.com/blog/ocaml-batteries-included-un-effort-pour-fournir-une-bibliotheque-standard-digne-de-ce-nom-pour-ocaml/</link>
		<comments>http://www.coder-studio.com/blog/ocaml-batteries-included-un-effort-pour-fournir-une-bibliotheque-standard-digne-de-ce-nom-pour-ocaml/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 20:36:57 +0000</pubDate>
		<dc:creator>Alp Mestan</dc:creator>
				<category><![CDATA[Langages fonctionnels]]></category>
		<category><![CDATA[batteries]]></category>
		<category><![CDATA[fonctionnel]]></category>
		<category><![CDATA[included]]></category>
		<category><![CDATA[ocaml]]></category>

		<guid isPermaLink="false">http://www.coder-studio.com/blog/?p=193</guid>
		<description><![CDATA[Bonsoir, Peut-être avez-vous déjà entendu parler de ce projet ... OCaml Batteries Included. Ce projet couvre pour le moment un certain nombre de domaines. Il fournit une certaine quantité de structures de données, de fonctions pour la programmation concurrente, etc. Qui plus est, il inclut des extensions de syntaxes qui pourront s'avérer très utile, ainsi [...]]]></description>
			<content:encoded><![CDATA[<p>Bonsoir,</p>
<p>Peut-être avez-vous déjà entendu parler de ce projet ... <a href="http://batteries.forge.ocamlcore.org/">OCaml Batteries Included</a>.</p>
<p>Ce projet couvre pour le moment un certain nombre de domaines. Il fournit une certaine quantité de structures de données, de fonctions pour la programmation concurrente, etc. Qui plus est, il inclut des extensions de syntaxes qui pourront s'avérer très utile, ainsi que de nouveaux opérateurs pour rendre le code OCaml plus lisible et concis, ce qui finalement fait gagner en lisibilité (notamment pour l'enchainement de fonctions, comme lorsque l'on appelle une série de fonctions opérant sur une chaîne de caractères, en passant le résultat d'une fonction à la suivante, et ainsi de suite). Je ne vais pas lister les bibliothèques, ce serait trop long.</p>
<p>OCaml Batteries Included est sortie en version Bêta 1 il y a quelques jours. Qui plus est, l'équipe OCaml-Debian-Maintainers a mis à disposition un paquet ocaml-batteries-included qui est dans le dépôt testing officiel, n'hésitez pas !</p>
<p>Pour finir, quelques liens :<br />
<a href="http://batteries.forge.ocamlcore.org/">Site officiel</a><br />
<a href="http://batteries.forge.ocamlcore.org/doc.preview:batteries-beta1/html/api/index.html">Documentation de l'API</a><br />
<a href="http://batteries.forge.ocamlcore.org/doc.preview:batteries-alpha3/html/index.html">Documentation de la plateforme</a><br />
<a href="http://dutherenverseauborddelatable.wordpress.com/2009/04/06/ocaml-batteries-included-beta-1/">Billet de blog sur la publication de la Beta 1</a></p>
<p>Enjoy !</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coder-studio.com/blog/ocaml-batteries-included-un-effort-pour-fournir-une-bibliotheque-standard-digne-de-ce-nom-pour-ocaml/feed/</wfw:commentRss>
		<slash:comments>2221</slash:comments>
		</item>
	</channel>
</rss>

