<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Alp Mestanogullari&#039;s Blog</title>
	<atom:link href="http://alpmestan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://alpmestan.wordpress.com</link>
	<description>C++, Haskell and Math for pleasure</description>
	<lastBuildDate>Mon, 10 Oct 2011 18:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='alpmestan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/303137a37e653e184da0958048f0132c?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Alp Mestanogullari&#039;s Blog</title>
		<link>http://alpmestan.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://alpmestan.wordpress.com/osd.xml" title="Alp Mestanogullari&#039;s Blog" />
	<atom:link rel='hub' href='http://alpmestan.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A French community for Haskell</title>
		<link>http://alpmestan.wordpress.com/2011/10/09/a-french-community-for-haskell/</link>
		<comments>http://alpmestan.wordpress.com/2011/10/09/a-french-community-for-haskell/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 22:17:58 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=133</guid>
		<description><![CDATA[During the past few months, there has been some growing activity in the (hidden) French circles of the Haskell community. A few people, including myself, are trying to increase the interest around Haskell in the French-speaking communities. You may (or may not) have noticed the translation of Learn You A Haskell that is available here, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=133&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>During the past few months, there has been some growing activity in the (hidden) French circles of the Haskell community. A few people, including myself, are trying to increase the interest around Haskell in the French-speaking communities. You may (or may not) have noticed the translation of <a href="http://www.lyah.org/" title="Learn You A Haskell" target="_blank">Learn You A Haskell</a> that is available <a href="http://lyah.haskell.fr/" title="French translation of LYAH" target="_blank">here</a>, in French. We also have an IRC channel, <em>#haskell-fr</em> (<a href="http://webchat.freenode.net/?channels=haskell-fr" target="_blank">access it through Freenode&#8217;s webchat</a>), and a <a href="http://www.haskell.org/mailman/listinfo/haskell-fr" title="haskell-fr mailing list" target="_blank">mailing list</a>. Please let us know about you if you are a French-speaking haskeller!</p>
<p>But we would like to get it a step further. We are currently considering the idea of a French hackathon. We already have been offered a room for 3 days in June 2012, in conjunction with a French Perl event. So one of the reasons behind this blog post is to get some feedback about this, in addition to letting people know about the French community. Who would be interested in attending such an event? This would be in Strasbourg, France for the moment. Note that this would not necessarily be restricted to French haskellers! The format would be a pretty much classical Hackathon: potential talks and a lot of Haskell hacking. So please let us know if you&#8217;d be interested in attending this (by commenting this post, the IRC channel or the mailing list).</p>
<p>On a side note, these past few days, I updated one of my libraries: <a href="http://hackage.haskell.org/package/statistics-linreg-0.2.1" title="statistics-linreg" target="_blank">statistics-linreg</a> and published one too: <a href="http://hackage.haskell.org/package/kmeans-vector" title="kmeans-vector" target="_blank">kmeans-vector</a>. It performs the <a href="http://en.wikipedia.org/wiki/K-means_clustering" target="_blank">k-means clustering algorithm</a> on a list of points, and can lead to &#8220;pretty&#8221; graphics like the following.</p>
<div id="attachment_140" class="wp-caption aligncenter" style="width: 310px"><a href="http://alpmestan.files.wordpress.com/2011/10/example.png"><img src="http://alpmestan.files.wordpress.com/2011/10/example.png?w=300&#038;h=225" alt="" title="Performing k-means on 10,000 points with 4 clusters" width="300" height="225" class="size-medium wp-image-140" /></a><p class="wp-caption-text">Performing k-means on 10,000 points with 5 clusters</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=133&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2011/10/09/a-french-community-for-haskell/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>

		<media:content url="http://alpmestan.files.wordpress.com/2011/10/example.png?w=300" medium="image">
			<media:title type="html">Performing k-means on 10,000 points with 4 clusters</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting GHC HEAD and LLVM working together</title>
		<link>http://alpmestan.wordpress.com/2010/03/11/getting-ghc-head-and-llvm-working-together/</link>
		<comments>http://alpmestan.wordpress.com/2010/03/11/getting-ghc-head-and-llvm-working-together/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 00:14:15 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[llvm]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=103</guid>
		<description><![CDATA[Since dons&#8217; two posts, I have seen many people on the haskell-cafe mailing-list and the haskell-related IRC channels asking how they could get GHC HEAD and the LLVM-related stuff, build them and all. There are a lot of this information on the ghc trac but I have been told it would be nice to have [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=103&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://donsbot.wordpress.com/2010/03/01/evolving-faster-haskell-programs-now-with-llvm/">dons&#8217;</a> <a href="http://donsbot.wordpress.com/2010/02/21/smoking-fast-haskell-code-using-ghcs-new-llvm-codegen/">two posts</a>, I have seen many people on <a href="http://www.haskell.org/pipermail/haskell-cafe/">the haskell-cafe mailing-list</a> and <a href="http://www.haskell.org/haskellwiki/IRC_channel">the haskell-related IRC channels</a> asking how they could get GHC HEAD and the LLVM-related stuff, build them and all. There are a lot of this information on the ghc trac but I have been told it would be nice to have a comprehensive guide with all the necessary steps and information. </p>
<h3>Getting, patching and building LLVM</h3>
<p>It is as simple as executing the following commands:</p>
<blockquote><p>$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm<br />
$ cd llvm<br />
$ patch -p0 -i ~/llvm-ghc.patch<br />
$ ./configure &#8211;enable-optimized # probably also want to set &#8211;prefix<br />
$ make<br />
$ make install</p></blockquote>
<p>where the given llvm-ghc.patch file can be downloaded here : <a href="http://www.cse.unsw.edu.au/~davidt/downloads/llvm-ghc.patch">http://www.cse.unsw.edu.au/~davidt/downloads/llvm-ghc.patch</a>.</p>
<h3>Getting GHC HEAD and Patching it to add the LLVM backend</h3>
<p>First, get the latest archive matching that pattern : <em>ghc-HEAD-AAAA-MM-JJ-ghc-corelibs-testsuite.tar.{gz or bz2}</em> at <a href="http://darcs.haskell.org/">http://darcs.haskell.org/</a>, the latest currently being <a href="http://darcs.haskell.org/ghc-HEAD-2009-10-23-ghc-corelibs-testsuite.tar.gz">ghc-HEAD-2009-10-23-ghc-corelibs-testsuite.tar.gz</a>. It ships GHC with all its dependencies, also including a testsuite.</p>
<p>Put the archive file in (on my computer) <em>/home/alp/haskell/</em>. Uncompress it with for example:</p>
<blockquote><p>$ tar xzf ghc-HEAD-2009-10-23-ghc-corelibs-testsuite.tar.gz</p></blockquote>
<p>You should get a <em>/home/alp/haskell/<strong>ghc/</strong></em> directory. Now we have to fetch the latest patches applied to GHC since the archive you downloaded got published on darcs.haskell.org. To do this, simply do:</p>
<blockquote><p>$ chmod +x ./darcs-all<br />
$ ./darcs-all pull -a</p></blockquote>
<p>(the former may not be necessary though)<br />
It can take some time, there may be a lot of patches to fetch and apply, don&#8217;t worry. </p>
<p>If you are not interested in having the LLVM backend, you can stop reading that section and go straight to the next one.</p>
<p>Once done with that, you have to download the patch to add the support to the LLVM backend to GHC. Just download the following file : <a href="http://www.cse.unsw.edu.au/~davidt/downloads/ghc-llvmbackend-full.gz">http://www.cse.unséw.edu.au/~davidt/downloads/ghc-llvmbackend-full.gz</a> (it actually just is a darcs patch, not an archive or anything else &#8212; you may want to rename it with a <em>.patch</em> extension), put it in ghc&#8217;s directory (<em>/home/alp/haskell/ghc/</em> here) and apply the patch :</p>
<blockquote><p>$ darcs apply ghc-llvmbackend-full.patch</p></blockquote>
<p> (or .gz)</p>
<p>You just have one more patch to apply (isn&#8217;t life about applying patches?), written by <a href="http://donsbot.wordpress.com/">Don Stewart</a>, to be able to pass LLVM options to GHC without conflicting with other options. You can get it at <a href="http://www.galois.com/~dons/add-new-llvm-code-generator-to-ghc_.dpatch">http://www.galois.com/~dons/add-new-llvm-code-generator-to-ghc_.dpatch</a>. Just move it to your ghc directory and <em>darcs apply</em> it, like you just did for the previous patch. (note: this step might not be necessary if the previous patch or the ghc repository contain it)</p>
<p>Ok, we are almost done! Now create a file named &#8220;build.mk&#8221; in (on my computer) <em>/home/alp/haskell/ghc/mk/</em>, and put the following content in that file:</p>
<blockquote><p>
GhcWithLlvmCodeGen = YES<br />
GhcEnableTablesNextToCode = NO
</p></blockquote>
<p>The first, obviously, enables LLVM code generation in GHC. The second disables a feature currently being in conflict between the LLVM and the C code generators, if I remember correctly. Now, let&#8217;s build GHC, hooray!</p>
<h3>Building and using the patched GHC non-intrusively</h3>
<p>Once all the patches are fetched and applied, you just have to do:</p>
<blockquote><p>$ sh boot<br />
$ ./configure<br />
$ make</p></blockquote>
<p>Now, have a cup of coffee, read newspapers, try to solve <em>P vs NP</em>, whatever. It takes some time.</p>
<p>Once done with &#8216;make&#8217;, there should be many binaries in (on my computer) <em>/home/alp/haskell/ghc/inplace/bin/</em>. The ghc binary is called <em>ghc-stage2</em></p>
<p>To check that the LLVM backend is enabled, as explained on Don&#8217;s post, just do the following (in the your ghc/inplace/bin/ directory):</p>
<blockquote><p>$ ghc-stage2 &#8211;info</p></blockquote>
<p>and verify that it gives you <em>(&#8220;Have llvm code generator&#8221;,&#8221;YES&#8221;)</em>.</p>
<p>To make use of them properly without installing your brand new GHC HEAD system-wide, here is one possibility; add the following to your ~/.bashrc (or whatever you use, it&#8217;s just about defining variables):</p>
<blockquote><p>GHC613 = /home/alp/haskell/ghc/inplace/bin<br />
GHC613BIN=$GHC613/ghc-stage2<br />
GHC613PKG=$GHC613/ghc-pkg</p></blockquote>
<p>And now, when you will want to install libraries via cabal for your new GHC, just execute commands close to the following (to install say the <em>vector</em> package):</p>
<blockquote><p>$ cabal install vector &#8211;with-compiler=$GHC613BIN &#8211;with-hc-pkg=$GHC613PKG</p></blockquote>
<p>And it will build and install the <em>vector</em> package using GHC HEAD and its library directories (in ~/.ghc/).<br />
Moreover, if you want to build packages with the llvm backend, just ask cabal gently:</p>
<blockquote><p>$ cabal install vector &#8211;with-compiler=$GHC613BIN &#8211;with-hc-pkg=$GHC613PKG &#8211;ghc-options=-fllvm</p></blockquote>
<p>You can even chain options this way, passing for example -optlo-03. For more informations on that, check Don&#8217;s posts:</p>
<ul>
<li><a href="http://donsbot.wordpress.com/2010/02/21/smoking-fast-haskell-code-using-ghcs-new-llvm-codegen/">Smoking fast Haskell code using GHC’s new LLVM codegen</a></li>
<li><a href="http://donsbot.wordpress.com/2010/03/01/evolving-faster-haskell-programs-now-with-llvm/">Evolving Faster Haskell Programs (now with LLVM!)</a></li>
</ul>
<p>But be careful, -fvia-C and -fllvm aren&#8217;t much friends, you may sometimes have to either edit the .cabal file of the package you want to install and removing -fvia-C from there, or via the &#8211;flags option of cabal install. For more informations, <em>cabal help install</em>.</p>
<p>Here are few links that you may find to be of interest:</p>
<ul>
<li><a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Backends/LLVM">Home of the LLVM backend section of GHC&#8217;s trac wiki</a></li>
<li><a href="http://hackage.haskell.org/trac/ghc/wiki/Building">The Building and Porting section of GHC&#8217;s trac wiki</a></li>
<li><a href="//www.cse.unsw.edu.au/~pls/thesis/davidt-thesis.pdf">David Terei&#8217;s thesis about the LLVM backend for GHC [PDF]</a> &#8212; thank you David !</li>
</ul>
<p>I hope this post will be of help and that it will lead some of you to contribute to GHC !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=103&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2010/03/11/getting-ghc-head-and-llvm-working-together/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>HNN news</title>
		<link>http://alpmestan.wordpress.com/2010/02/08/hnn-news/</link>
		<comments>http://alpmestan.wordpress.com/2010/02/08/hnn-news/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 15:19:20 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[hnn]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=98</guid>
		<description><![CDATA[Indeed, HNN moved to haskell.org and is growing. Firstly, the code is no longer evolving at github. There are at least 2 other persons working on HNN for the moment (Thomas Bereknyei and Jorden Mauro &#8212; thank you guys for joining the project) thus we decided it was high time having a bit more than [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=98&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Indeed, HNN moved to <a href="http://trac.haskell.org/HNN/">haskell.org</a> and is growing.</p>
<p>Firstly, the code is no longer evolving at github. There are at least 2 other persons working on HNN for the moment (Thomas Bereknyei and Jorden Mauro &#8212; thank you guys for joining the project) thus we decided it was high time having a bit more than a little github place. So we now have <a href="http://code.haskell.org/HNN/">a darcs repository</a>, <a href="http://projects.haskell.org/cgi-bin/mailman/listinfo/hnn">a mailing list</a> and <a href="http://trac.haskell.org/HNN/">a trac wiki / bug report system</a>.</p>
<p>As said on the trac home page, we are rewriting HNN from scratch to make it more generic and efficient. We will of course still make the API as simple as possible, fitting one of the most important goals of the original version of HNN.</p>
<p>Stay tuned !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/98/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/98/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/98/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=98&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2010/02/08/hnn-news/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>[French post] Présentation sur la programmation fonctionnelle</title>
		<link>http://alpmestan.wordpress.com/2010/02/06/french-post-presentation-sur-la-programmation-fonctionnelle/</link>
		<comments>http://alpmestan.wordpress.com/2010/02/06/french-post-presentation-sur-la-programmation-fonctionnelle/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 00:06:37 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[french]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=87</guid>
		<description><![CDATA[Bonsoir, Pour ceux qui ont assisté au talk sur la présentation fonctionnelle avec illustration en Haskell au Provence Linux User Group et qui voudraient revivre ce grand moment, je mets donc à disposition les slides ainsi que le code du bot IRC plugfrbot. Si j&#8217;ai le temps, un jour j&#8217;en ferai un superbot, avec protection [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=87&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Bonsoir,</p>
<p>Pour ceux qui ont assisté au talk sur la présentation fonctionnelle avec illustration en Haskell au <a href="http://www.plugfr.org/">Provence Linux User Group</a> et qui voudraient revivre ce grand moment, je mets donc à disposition les slides ainsi que le code du bot IRC <em>plugfrbot</em>. Si j&#8217;ai le temps, un jour j&#8217;en ferai un superbot, avec protection contre toutes les attaques possibles&#8230; Donc probablement jamais.</p>
<p>Slides : <a href="http://alpmestan.files.wordpress.com/2010/02/fp.pdf">Programmation Fonctionnelle (Présentation &#8211; PDF)</a></p>
<p>Code : <a href="http://mestan.fr/plug/plugfrbot.hs">Programmation Fonctionnelle &#8211; Bot <em>plugfrbot</em> (Code Haskell &#8211; .hs)</a></p>
<p>Peut-être à bientôt pour une présentation en lien avec la PF.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/87/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/87/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/87/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=87&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2010/02/06/french-post-presentation-sur-la-programmation-fonctionnelle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>Some thoughts on Haskell library design</title>
		<link>http://alpmestan.wordpress.com/2010/01/09/some-thoughts-on-haskell-library-design/</link>
		<comments>http://alpmestan.wordpress.com/2010/01/09/some-thoughts-on-haskell-library-design/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 22:02:31 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[hnn]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=77</guid>
		<description><![CDATA[Hi, Few weeks ago, I released a first (experimental) version of my Haskell Neural Network library. And since then, I have been thinking about the design of this library (and got some feedbacks from haskellers) : how to improve it, how to let people easily plug their stuffs in it, etc. In this post I&#8217;ll [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=77&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Few weeks ago, I released a first (experimental) version of my <a href="http://www.haskell.org/haskellwiki/HNN">Haskell Neural Network</a> library.</p>
<p>And since then, I have been thinking about the design of this library (and got some feedbacks from haskellers) : how to improve it, how to let people easily plug their stuffs in it, etc. In this post I&#8217;ll try to share my thoughts about how HNN can be improved (without anything neural network specific). I hope it will somehow be useful to someone.</p>
<h3>Typeclasses &#8212; &#8220;Is it really worth creating a typeclass for &#8230; ?&#8221;</h3>
<p>Let&#8217;s first replace this in its context. I like very much the typeclass feature of Haskell, I already used it for many things. But hey, HNN is a project for the Haskell community, I just can&#8217;t throw some typeclasses in it without actually thinking about why it would be good, and why it wouldn&#8217;t. Wouldn&#8217;t it be overkill and thus make  haskell code using HNN less nice ?</p>
<p>In my case, it is about the list-of-value storage. I started to store the weights and the inputs/outputs with lists of double. Pretty inefficient yeah, but I was rather prototyping than seriously writing the library. Then I moved to the uvector package, on Hackage. Way more efficient. But, you may wonder the following : &#8220;what would he do if we have an even nicer and more efficient container ?&#8221; &#8212; and you&#8217;re right. For the moment, intern stuffs are stored in an UArr and I provide both a list-based interface and an UArr-based one. But, hell, it&#8217;s already annoying to maintain both of these ! But I couldn&#8217;t at that moment look at my code with enough hindsight to get the good and the bad and actually operate the necessary changes to make it for the release of the 0.1 version.</p>
<p>A possible plan for the next version is to have a typeclass representing Storage related functions, and instanciate it for UArr and List. Then I&#8217;d abstract the functions that I have to call differently for List, UArr and all in the Storage typeclass and thus would only require an instance of <em>Storage</em> to be given to the functions I need. This way, if you have some container in some other part of your project, or if you just want to have a more performant / specific container store your values, it&#8217;ll be possible, provided you will give the necessary functions at the typeclass instanciation.</p>
<p>Now that I shared my reasonning path, yeah, obviously, there will be a typeclass for value storing. I even have some ideas about other uses for typeclasses, in particular one being suggested by Thomas Bereknyei : it would represent a computation. Why would it be interesting ? So that we could have complex computation units within neural networks, or interacting with neural networks. I&#8217;m particularly thinking of Kohonen Maps or recurrent neural networks. </p>
<h3>About &#8220;exposed function granularity&#8221;</h3>
<p>Maybe you already wondered whether you should expose few functions covering most of the tasks you library accomplishes or if you should rather provide many functions for little tasks. First, I don&#8217;t think there&#8217;s an universal answer to that question. It highly depends on the &#8220;combinatorial&#8221; capacity of the underlying concepts. For example, parsec provides many little functions because using parsec consists in combining these little functions to create more complex parsers. With neural networks, we don&#8217;t have that much of a combinatorial power. I mean, you create your neural network, apply training functions on it, and then use it. And the library does not have (yet) enough maturity to provide features like neural network combinations or so. So what&#8217;s the best for HNN ?</p>
<p>For the moment, we only have few functions doing almost all the job, giving them parameters to have the necessary flexibility to train the neural network with the smoothness we want, etc. I think it might be interesting to provide something similar to data structure folding for the neural networks, or even consider offering a graph-oriented interface (after all, that&#8217;s what neural networks are) and provide graph traversal functions to operate on the neural network. The key point here is to &#8211; whatever way I choose &#8211; provide higher order functions to operate on the neural networks, in addition to the simple and straighforward functions we can find in the library for the moment.</p>
<h3>Conclusions</h3>
<p>I will try to introduce some typeclasses to offer more flexibility to the future users, the number one priority being for the value storage. In addition to that, I have to provide users functions offering them to do nearly anything they want on the neural network, like we have folds for lists, trees and all. If these both goals are satisfied in a close future, HNN should definitely be more interesting for serious use. Another point I have to consider is to offer even better performances since neural networks &#8220;just&#8221; compute stuffs. UArr helped a lot for that, but I&#8217;m pretty sure I can introduce other improvements on that aspect of HNN. I just need to read again some pages of the GHC manual <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I hope these thoughts will be useful to someone. At least, they have been to me. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=77&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2010/01/09/some-thoughts-on-haskell-library-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>HNN-0.1 has been released !</title>
		<link>http://alpmestan.wordpress.com/2009/12/23/hnn-0-1-has-been-released/</link>
		<comments>http://alpmestan.wordpress.com/2009/12/23/hnn-0-1-has-been-released/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 15:09:09 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[hnn]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=75</guid>
		<description><![CDATA[Hi, I just released the 0.1 version of my Haskell Neural Network library on Hackage. Instead of writing a long blog post, I created a page on the Haskell wiki that you can find here : HNN describing what is HNN, how to get it, showing a sample and all. There is an online version [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=75&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>I just released the 0.1 version of my <strong>H</strong>askell <strong>N</strong>eural <strong>N</strong>etwork library on Hackage.<br />
Instead of writing a long blog post, I created a page on the Haskell wiki that you can find here : <a href="http://www.haskell.org/haskellwiki/HNN">HNN</a> describing what is HNN, how to get it, showing a sample and all.</p>
<p>There is an online version of the documentation here : <a href="http://mestan.fr/haskell/hnn/">hnn documentation</a><br />
You can also consult hnn&#8217;s hackage page : <a href="http://hackage.haskell.org/package/hnn-0.1">hnn at hackage</a> (the documentation should be generated soon there)</p>
<p>Here is a sample showing how you can use HNN :</p>
<p>module Main where</p>
<p>import AI.HNN.Net<br />
import AI.HNN.Layer<br />
import AI.HNN.Neuron<br />
import Data.Array.Vector<br />
import Control.Arrow<br />
import Data.List</p>
<p>alpha = 0.8 :: Double &#8212; learning ratio<br />
epsilon = 0.001 :: Double &#8212; desired maximal bound for the quad error</p>
<p>layer1, layer2 :: [Neuron]</p>
<p>layer1 = createSigmoidLayer 4 0.5 [0.5, 0.5, 0.5] &#8212; the hidden layer</p>
<p>layer2 = createSigmoidLayer 1 0.5 [0.5, 0.4, 0.6, 0.3] &#8212; the output layer</p>
<p>net = [layer1, layer2] &#8212; the neural network</p>
<p>finalnet = train alpha epsilon net [([1, 1, 1],[0]), ([1, 0, 1],[1]), ([1, 1, 0],[1]), ([1, 0, 0],[0])] &#8212; the trained neural network</p>
<p>good111 = computeNet finalnet [1, 1, 1]<br />
good101 = computeNet finalnet [1, 0, 1]<br />
good110 = computeNet finalnet [1, 1, 0]<br />
good100 = computeNet finalnet [1, 0, 0]</p>
<p>main = do<br />
     putStrLn $ &quot;Final neural network : \n&quot; ++ show finalnet<br />
     putStrLn &quot; &#8212;- &quot;<br />
     putStrLn $ &quot;Output for [1, 1, 1] (~ 0): &quot; ++ show good111<br />
     putStrLn $ &quot;Output for [1, 0, 1] (~ 1): &quot; ++ show good101<br />
     putStrLn $ &quot;Output for [1, 1, 0] (~ 1): &quot; ++ show good110<br />
     putStrLn $ &quot;Output for [1, 0, 0] (~ 0): &quot; ++ show good100</p>
<p>Output :</p>
<blockquote><p>
$ ./xor-3inputs<br />
Final neural network :<br />
[[Threshold : 0.5<br />
Weights : toU [1.30887603787326,1.7689534867644316,2.2908214981696453],Threshold : 0.5<br />
Weights : toU [-2.4792430791673947,4.6447786039112655,-4.932860802255383],Threshold : 0.5<br />
Weights : toU [2.613377735822592,6.793687725768354,-5.324081206358496],Threshold : 0.5<br />
Weights : toU [-2.5134194114492585,4.730152273922408,-5.021321916827272]],[Threshold : 0.5<br />
Weights : toU [4.525235803191061,4.994126671590998,-8.2102354168462,5.147655509585701]]]<br />
 &#8212;-<br />
Output for [1, 1, 1] (~ 0): [2.5784449476436315e-2]<br />
Output for [1, 0, 1] (~ 1): [0.9711209812630944]<br />
Output for [1, 1, 0] (~ 1): [0.9830499812666017]<br />
Output for [1, 0, 0] (~ 0): [1.4605247804272069e-2]
</p></blockquote>
<p>Don&#8217;t hesitate to try it, play with it and give some feedback ! For any feedback or question, see <a href="http://www.haskell.org/haskellwiki/HNN#Feedback.2C_participation_and_all">the end of the HNN wiki page</a>.</p>
<p>Thanks, and enjoy !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/75/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/75/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/75/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=75&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2009/12/23/hnn-0-1-has-been-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>HNN : a Haskell Neural Network library</title>
		<link>http://alpmestan.wordpress.com/2009/12/22/hnn-a-haskell-neural-network-library/</link>
		<comments>http://alpmestan.wordpress.com/2009/12/22/hnn-a-haskell-neural-network-library/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 03:09:49 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AI]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[hnn]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=72</guid>
		<description><![CDATA[Hi, Few months ago, I started working on a neural network library, in Haskell. The result wasn&#8217;t that bad, but needed some additional work. Past days, I&#8217;ve worked a bit on that code again to get a releasable and usable 0.1 version of HNN up and working. For example, the weights, inputs and outputs are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=72&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Few months ago, I started working on a neural network library, in Haskell. The result wasn&#8217;t that bad, but needed some additional work. Past days, I&#8217;ve worked a bit on that code again to get a releasable and usable 0.1 version of HNN up and working. For example, the weights, inputs and outputs are of type <em><a href="http://hackage.haskell.org/packages/archive/uvector/0.1.1.0/doc/html/Data-Array-Vector.html#t%3AUArr">UArr</a> Double</em> now (they were of type [Double] before). </p>
<p>You can find the source code there : <a href="http://github.com/alpmestan/HNN">http://github.com/alpmestan/HNN</a>.<br />
Also, I&#8217;ve built a minimal documentation. You can find it here : <a href="http://mestan.fr/haskell/hnn/">http://mestan.fr/haskell/hnn/</a>.</p>
<p>To get the current code and test it :</p>
<blockquote><p>$ git clone git://github.com/alpmestan/HNN.git<br />
$ cd HNN<br />
$ cabal configure<br />
$ cabal build<br />
$ cabal install (to add it in your ghc package list, etc)<br />
$ cabal haddock (to generate the documentation)</p></blockquote>
<p>I plan to put this on Hackage soon, but I would like to get some feedback &amp; reviews about it before.</p>
<p>Thank you !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/72/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/72/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/72/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=72&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2009/12/22/hnn-a-haskell-neural-network-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>Functional compile-time templates based type lists in C++</title>
		<link>http://alpmestan.wordpress.com/2009/12/03/functional-compile-time-templates-based-type-lists-in-c/</link>
		<comments>http://alpmestan.wordpress.com/2009/12/03/functional-compile-time-templates-based-type-lists-in-c/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 09:12:48 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=69</guid>
		<description><![CDATA[Hi, Have you ever heard about typelists in C++ ? That just consists in using the functional way of defining lists, but with templates. It looks like that : However, we&#8217;ll need a type representing an empty type list. Ours will be the following. How to write metafunctions (compile-time functions, working over types and not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=69&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p>Have you ever heard about  typelists in C++ ? That just consists in using the functional way of defining lists, but with templates.<br />
It looks like that :</p>
<pre class="brush: cpp;">
template &lt;typename Head, typename Tail&gt;
struct TypeList
{
  typedef Head head;
  typedef Tail tail;
};
</pre>
<p>However, we&#8217;ll need a type representing an empty type list. Ours will be the following.</p>
<pre class="brush: cpp;">
struct EmptyList { };
</pre>
<p>How to write metafunctions (compile-time functions, working over types and not values &#8212; actually, the types are in this context like &#8220;values&#8221;) for these type lists now ?</p>
<p>Let&#8217;s start with a metafunction computing the length of a type list :</p>
<pre class="brush: cpp;">
// declaration
template &lt;typename Typelist&gt;
struct Length;

// the normal case : the head element of the list (it's a type), and the tail, which is itself a type list
template &lt;typename H, typename T&gt;
struct Length&lt;TypeList&lt;H, T&gt; &gt;
{
  static const int value = 1 + Length&lt;T&gt;::value ;
};

// the terminal case : our typelist is the empty list, we're at the end of the list, so we won't add 1 neither we will go on with the recursion
template &lt;&gt;
struct Length&lt;EmptyList&gt;
{
  static const int value = 0 ;
};
</pre>
<p>Now, calling it on a given typelist will return us the good result :</p>
<pre class="brush: cpp;">
Length&lt; TypeList&lt;int, TypeList&lt;char, TypeList&lt;bool, EmptyList&gt; &gt; &gt; &gt;::value // equals 3
</pre>
<p>Do you want more ? I guess you do, of course. Let&#8217;s tackle a more complicated one : Map. It maps a type list to another one, computing the result of the application of a metafunction on each type of the type list. Ok, let&#8217;s start with the declaration.</p>
<pre class="brush: cpp;">
template &lt;typename TL, template &lt;typename&gt; class Func&gt;
struct Map;
</pre>
<p>Now, the basical case, with a head element and the tail, will consist in computing the result of the application of the metafunction of the head element, and appending to it the result of Map on the tail. Looks like that :</p>
<pre class="brush: cpp;">
template &lt;typename H, typename T, template &lt;typename&gt; class Func&gt;
struct Map&lt;TypeList&lt;H, T&gt;, Func&gt;
{
  typedef TypeList&lt; typename Func&lt;H&gt;::type, typename Map&lt;T, Func&gt;::type &gt; type;
};
</pre>
<p>And the trivial case, on the empty list :</p>
<pre class="brush: cpp;">
template &lt;template &lt;typename&gt; class Func&gt;
struct Map&lt;EmptyList, Func&gt;
{
  typedef EmptyList type;
};
</pre>
<p>And we&#8217;re done with Map !</p>
<p>Let&#8217;s see one more interesting function over type lists : Filter. It&#8217;ll filter (really ?!) the type list according to a compile-time predicate, and return the original type list without the types that didn&#8217;t match the predicate.<br />
Here we go !</p>
<pre class="brush: cpp;">
template &lt;typename TypeList, template &lt;typename&gt; class Pred&gt;
struct Filter;

template &lt;typename H, typename T, template &lt;typename&gt; class Pred, bool result&gt;
struct FilterAux
{
  typedef typename Filter&lt;T, Pred&gt;::type type;
};

template &lt;typename H, typename T, template &lt;typename&gt; class Pred&gt;
struct FilterAux&lt;H, T, Pred, true&gt;
{
  typedef TypeList&lt;H, typename Filter&lt;T, Pred&gt;::type&gt; type;
};

template &lt;typename H, typename T, template &lt;typename&gt; class Pred&gt;
struct Filter&lt;TypeList&lt;H, T&gt;, Pred&gt;
{
  typedef typename FilterAux&lt;H, T, Pred, Pred&lt;H&gt;::value&gt;::type type;
};

template &lt;template &lt;typename&gt; class Pred&gt;
struct Filter&lt;EmptyList, Pred&gt;
{
  typedef EmptyList type;
};
</pre>
<p>This one was trickier, because we needed an auxiliary template structure to have a bool against which we could specialize, to either go on without keeping the type in the type list (in case it doesn&#8217;t match the predicate) or keeping it.</p>
<p>Now, I&#8217;ll leave as exercise the following functions :<br />
- Repeat : takes a  type, a number, and returns a type list containing n times the given type<br />
- Take : takes a type list and a number, and returns a type list contaning the first n elements of the typelist if possible, less otherwise.<br />
- Interleave : it takes 2 two lists, say l1 = [T1, T2, T3] and l2 = [U1, U2, U3] and returns the list [T1, U1, T2, U2, T3, U3]<br />
- Zip : takes two lists and returns a list of component-wise pairs of the types<br />
- ZipWith : takes two lists and a function itself taking two types and returning a type, and returns a list compound of the component-wise application of the given function on both lists simultaneously</p>
<p>I&#8217;ll try to post these during the upcoming days.</p>
<p>Good functional metaprogramming to all <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=69&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2009/12/03/functional-compile-time-templates-based-type-lists-in-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
		<item>
		<title>Why expression templates matter ?</title>
		<link>http://alpmestan.wordpress.com/2009/11/01/why-expression-templates-matter/</link>
		<comments>http://alpmestan.wordpress.com/2009/11/01/why-expression-templates-matter/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 19:34:36 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[dsel]]></category>
		<category><![CDATA[expression templates]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=58</guid>
		<description><![CDATA[Imagine we are using a matrix library, with a naive implementation of +, that simply adds column and row-wise each coefficient. Thus, for a, m1, m2, m3 being for example square matrices of order n, if we want to compute the sum of m1, m2 and m3 and to put the result in a, corresponding [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=58&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Imagine we are using a matrix library, with a naive implementation of +, that simply adds column and row-wise each coefficient. Thus, for a, m1, m2, m3 being for example square matrices of order n, if we want to compute the sum of m1, m2 and m3 and to put the result in a, corresponding to the following code :</p>
<pre class="brush: cpp;">
a = m1 + m2 + m3
</pre>
<p>then the computation will look like the following tree :</p>
<div id="attachment_61" class="wp-caption aligncenter" style="width: 237px"><a href="http://alpmestan.files.wordpress.com/2009/11/exprtpl1.png"><img src="http://alpmestan.files.wordpress.com/2009/11/exprtpl1.png?w=227&#038;h=251" alt="Evaluation tree of m1 + m2 + m3" title="Evaluation tree of m1 + m2 + m3" width="227" height="251" class="size-full wp-image-61" /></a><p class="wp-caption-text">Evaluation tree of m1 + m2 + m3</p></div>
<p>Thus, there will be a first for loop to compute <em>m1 + m2</em> which will result in a matrix we&#8217;ll call <em>t</em>, then another one to compute <em>t + m3</em>. For 3&#215;3 matrices, it&#8217;s ok. Imagine n is actually 40000. Doing two for loops of 40000 iterations where we would do a single one&#8230; quite annoying, isn&#8217;t it ? Actually, we would rather want an evaluation tree like the following :</p>
<div id="attachment_63" class="wp-caption aligncenter" style="width: 285px"><a href="http://alpmestan.files.wordpress.com/2009/11/exprtpl2.png"><img src="http://alpmestan.files.wordpress.com/2009/11/exprtpl2.png?w=275&#038;h=155" alt="The desired evaluation tree of m1 + m2 + m3" title="The desired evaluation tree of m1 + m2 + m3" width="275" height="155" class="size-full wp-image-63" /></a><p class="wp-caption-text">The desired evaluation tree of m1 + m2 + m3</p></div>
<p>Here comes expression templates <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>It&#8217;ll need a bit of refactoring though. First, let&#8217;s say our matrix type is the following (we&#8217;ll only deal with float to avoid ambedding an additional typename template parameter representing the number type we use) :</p>
<pre class="brush: cpp;">
template &lt;unsigned int N&gt;
class matrix
{
    float data[N*N];

public:
    float operator()(unsigned int row, unsigned int col) const
    {
        return data[row + N*col];
    }

    float&amp; operator()(unsigned int row, unsigned int col)
    {
        return data[row + N*col];
    }
};

template &lt;unsigned int N&gt;
std::ostream &amp; operator&lt;&lt;(std::ostream&amp; o, const matrix&lt;N&gt;&amp; m)
{
    o &lt;&lt; &quot;[&quot;;
    for(unsigned int row = 0; row &lt; N; row++)
    {
        for(unsigned int col = 0; col &lt; N; col++)
        {
            o &lt;&lt; m(row,col);
            if(col != N-1) o &lt;&lt; &quot;;&quot;;
        }
        if(row != N-1) o &lt;&lt; &quot;\n&quot;;
    }
    o &lt;&lt; &quot;]&quot;;
    return o;
}
</pre>
<p>Now, we&#8217;ll have to define a <strong>Domain Specific Embedded Language</strong> for matrix operations. Like in any language people design, we will have a tree representing what&#8217;s happening in the code. In our case, it&#8217;ll represent the evaluation tree of the matrix operations we&#8217;re dealing with. Thus, like in any expression tree, we need an <em>Expression</em> type. Ours will look like this :</p>
<pre class="brush: cpp;">
template &lt;typename LeftOperandType, typename OperationTag, typename RightOperandType&gt;
struct Expression
{
    const LeftOperandType&amp; l;
    const RightOperandType&amp; r;

    Expression(const LeftOperandType&amp; l_, const RightOperandType&amp; r_) : l(l_), r(r_) { }

    float operator() (unsigned int row, unsigned int col) const
    {
        return OperationTag::apply(l(row, col), r(row,col));
    }
};
</pre>
<p>Ok, now, what should an <em>OperationTag</em> look like ? Well, we&#8217;ll implement the operation tag corresponding to additions :</p>
<pre class="brush: cpp;">
struct plus
{
    static float apply(float a, float b)
    {
        return a+b;
    }
};
</pre>
<p>and the <em>+ operator</em> that&#8217;ll let us create an expression with a &#8216;plus&#8217; operation.</p>
<pre class="brush: cpp;">
template &lt;typename L, typename R&gt;
Expression&lt;L, plus, R&gt; operator+(const L&amp; l, const R&amp; r)
{
    return Expression&lt;L, plus, R&gt;(l, r);
}
</pre>
<p>Thanks to the definition of <em>Expression</em>, we can embed matrix operations in Expressions, but for the moment we can&#8217;t do the reverse way, that is we can&#8217;t convert an <em>Expression</em> to a <em>matrix</em>. So let&#8217;s write an <em>operator=</em> in the <em>matrix</em> class.</p>
<pre class="brush: cpp;">
    // inside the matrix class
    template &lt;typename ExprType&gt;
    matrix&lt;N&gt;&amp; operator=(const ExprType&amp; e)
    {
        for(unsigned int row = 0; row &lt; N; row++)
        {
            for(unsigned int col = 0; col &lt; N; col++)
            {
                (*this)(row, col) = e(row, col);
            }
        }
        return (*this);
    }
</pre>
<p>So you see, this is the only moment where we call the <em>operator()(unsigned int, unsigned int)</em> of the <em>Expression</em> type. Thus, this is the only moment when the whole expression is being evaluated. Let&#8217;s study the following code.</p>
<pre class="brush: cpp;">
#include &lt;iostream&gt;
#include &quot;matrix.h&quot;
#include &quot;expression.h&quot;

int main()
{
    matrix&lt;2&gt; m1;
    m1(0,0) = 1.0;
    m1(1,0) = 0.0;
    m1(0,1) = 4.0;
    m1(1,1) = 1.0;

    matrix&lt;2&gt; m2;
    m2(0,0) = 0.0;
    m2(1,0) = -1.0;
    m2(0,1) = 1.0;
    m2(1,1) = 2.0;

    matrix&lt;2&gt; m3;
    m3(0,0) = 1.0;
    m3(1,0) = -2.0;
    m3(0,1) = 3.0;
    m3(1,1) = 5.0;

    matrix&lt;2&gt; a;
    a = m1 + m2 + m3;
    std::cout &lt;&lt; a &lt;&lt; std::endl;
}
</pre>
<p>Here, &#8220;m1 + m2 + m3&#8243; crates an
<pre class="brush: cpp;">Expression&lt; Expression&lt;matrix&lt;2&gt;, plus, matrix&lt;2&gt; &gt;, plus, matrix&lt;2&gt; &gt;</pre>
<p>instance. The coefficients aren&#8217;t computed until <em>operator=</em> is called. Indeed, we have the following expression tree.</p>
<div id="attachment_66" class="wp-caption aligncenter" style="width: 310px"><a href="http://alpmestan.files.wordpress.com/2009/11/exprtpl31.png"><img src="http://alpmestan.files.wordpress.com/2009/11/exprtpl31.png?w=300&#038;h=90" alt="Expression tree" title="Expression tree" width="300" height="90" class="size-medium wp-image-66" /></a><p class="wp-caption-text">Expression tree</p></div>
<p>That is, we know which operations we have to call, on which matrices, but nothing is evaluated. The only place where we call <em>operator() (unsigned int, unsigned int)</em> on a value of type <em>Expression</em> is in <em>matrix&lt;N&gt;::operator=</em>, and this call actually computes each coefficient, one by one, applying the whole computation tree (here, two calls to &#8216;+&#8217;) for each coefficient. This way, we only execute the two for loops once, and it&#8217;ll remain the same whatever the number of computations is. Moreover, the only change we had to make to our matrix class was to add an operator= to be able to assign an expression to a matrix.</p>
<p>By the way, the output of our main function is the following.</p>
<blockquote><p>
[2;8<br />
-3;8]
</p></blockquote>
<p>I hope you enjoyed this post <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=58&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2009/11/01/why-expression-templates-matter/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>

		<media:content url="http://alpmestan.files.wordpress.com/2009/11/exprtpl1.png" medium="image">
			<media:title type="html">Evaluation tree of m1 + m2 + m3</media:title>
		</media:content>

		<media:content url="http://alpmestan.files.wordpress.com/2009/11/exprtpl2.png" medium="image">
			<media:title type="html">The desired evaluation tree of m1 + m2 + m3</media:title>
		</media:content>

		<media:content url="http://alpmestan.files.wordpress.com/2009/11/exprtpl31.png?w=300" medium="image">
			<media:title type="html">Expression tree</media:title>
		</media:content>
	</item>
		<item>
		<title>Templates for unique id generation for types : a beginning</title>
		<link>http://alpmestan.wordpress.com/2009/10/31/templates-for-unique-id-generation-for-types-a-beginning/</link>
		<comments>http://alpmestan.wordpress.com/2009/10/31/templates-for-unique-id-generation-for-types-a-beginning/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 04:57:16 +0000</pubDate>
		<dc:creator>alpmestan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[templates]]></category>

		<guid isPermaLink="false">http://alpmestan.wordpress.com/?p=45</guid>
		<description><![CDATA[After reading one of the comments on this blog post, I decided to publish here a proof of concept for the generation of unique ids for types. Basically, it&#8217;s just about one template structure, using very basical templates techniques : specialization, metaprogramming-level recursion and nested enum for the computation. Either a familiarity with template metaprogramming [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=45&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After reading one of the comments on <a href="http://cplusplus.co.il/2009/10/25/computing-the-level-of-indirection-for-pointer-types/">this blog post</a>, I decided to publish here a proof of concept for the generation of unique ids for types.</p>
<p>Basically, it&#8217;s just about one template structure, using very basical templates techniques : specialization, metaprogramming-level recursion and nested enum for the computation. Either a familiarity with template metaprogramming or with functional programming is enough to understand the following code.</p>
<p>If you&#8217;re familiar with any scheme of functional recursion, or recursion in its mathematical sense, you&#8217;ll get it quite easily. Mathematically, we&#8217;re somehow defining a recursive function <em>generate_id</em> this way :</p>
<p><img src='http://s0.wp.com/latex.php?latex=generateid%28int%29+%3D+5&amp;bg=fff&amp;fg=222&amp;s=0' alt='generateid(int) = 5' title='generateid(int) = 5' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=generateid%28char%29+%3D+7&amp;bg=fff&amp;fg=222&amp;s=0' alt='generateid(char) = 7' title='generateid(char) = 7' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=%5Cforall+T%2C%5C%2C+generateid%28%5Ctextit%7Bpointer+to+T%7D%29+%3D+2+%5Ccdot+generateid%28T%29&amp;bg=fff&amp;fg=222&amp;s=0' alt='&#92;forall T,&#92;, generateid(&#92;textit{pointer to T}) = 2 &#92;cdot generateid(T)' title='&#92;forall T,&#92;, generateid(&#92;textit{pointer to T}) = 2 &#92;cdot generateid(T)' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=%5Cforall+T%2C%5C%2C+generateid%28%5Ctextit%7Bref+to+T%7D%29+%3D+3+%5Ccdot+generateid%28T%29&amp;bg=fff&amp;fg=222&amp;s=0' alt='&#92;forall T,&#92;, generateid(&#92;textit{ref to T}) = 3 &#92;cdot generateid(T)' title='&#92;forall T,&#92;, generateid(&#92;textit{ref to T}) = 3 &#92;cdot generateid(T)' class='latex' /><br />
<img src='http://s0.wp.com/latex.php?latex=%5Cforall+T%2C%5C%2C+generateid%28%5Ctextit%7Bvector+of+T%7D%29+%3D+11+%5Ccdot+generateid%28T%29&amp;bg=fff&amp;fg=222&amp;s=0' alt='&#92;forall T,&#92;, generateid(&#92;textit{vector of T}) = 11 &#92;cdot generateid(T)' title='&#92;forall T,&#92;, generateid(&#92;textit{vector of T}) = 11 &#92;cdot generateid(T)' class='latex' /></p>
<p>Which, in C++, becomes :</p>
<pre class="brush: cpp;">
template &lt;typename T&gt;
struct id_generator;

template &lt;typename T&gt;
struct id_generator&lt;T*&gt;
{
    enum { result = id_generator&lt;T&gt;::result*2 };
};

template &lt;typename T&gt;
struct id_generator&lt;T&amp;&gt;
{
    enum { result = id_generator&lt;T&gt;::result*3 };
};

template &lt;typename T&gt;
struct id_generator&lt; std::vector&lt;T&gt; &gt;
{
    enum { result = id_generator&lt;T&gt;::result*11 };
};

template &lt;&gt;
struct id_generator&lt;int&gt;
{
    enum { result = 5 };
};

template &lt;&gt;
struct id_generator&lt;char&gt;
{
    enum { result = 7 };
};
</pre>
<p>And a minimal example of use :</p>
<pre class="brush: cpp;">
int main()
{
    std::cout &lt;&lt; &quot;int : &quot; &lt;&lt; id_generator&lt; int &gt;::result &lt;&lt; std::endl
              &lt;&lt; &quot;char**** : &quot; &lt;&lt; id_generator&lt; char**** &gt;::result &lt;&lt; std::endl
              &lt;&lt; &quot;vector&lt;int&gt; : &quot; &lt;&lt; id_generator&lt; std::vector&lt;int&gt; &gt;::result &lt;&lt; std::endl;
    return 0;
}
/* Output :
int : 5
char**** : 112
vector&lt;int&gt; : 55
*/
</pre>
<p>To make it really usable, you&#8217;ll have to add much (much much much) more :</p>
<ul>
<li>base types, like int and char here, which help for terminating the recursive call</li>
<li>composition rules, like vector, references and pointers here, which help for propagating the recursion</li>
</ul>
<p>To ensure the uniqueness here, I use prime numbers, simply [1]. Indeed, for the base types, I give a value being a prime number. For the different compositions, I multiply by a different prime number for each. However, most of you may have noticed that the id only lets you know about what type compositions and base types are used, but gives nothing about the order. If we add a rule for std::list, multiplying by 13 for example, then <em>a list of vectors of ints</em> will have the same id as <em>a vector of lists of int</em>. It&#8217;d need additional code and workarounds to take the order of the compositions in account &#8212; I guess it is possible though. If any reader here comes up with a solution, let us know. A possible solution would be to drop prime numbers, since they rely on a commutative (abelian) ring [2].</p>
<p>[1] <a href="http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic">http://en.wikipedia.org/wiki/Fundamental_theorem_of_arithmetic</a><br />
[2] <a href="http://en.wikipedia.org/wiki/Commutative_ring">http://en.wikipedia.org/wiki/Commutative_ring</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/alpmestan.wordpress.com/45/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/alpmestan.wordpress.com/45/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/alpmestan.wordpress.com/45/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=alpmestan.wordpress.com&amp;blog=9675597&amp;post=45&amp;subd=alpmestan&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://alpmestan.wordpress.com/2009/10/31/templates-for-unique-id-generation-for-types-a-beginning/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11ba6dfa8271fb1cd0c475a2c0626853?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">alpmestan</media:title>
		</media:content>
	</item>
	</channel>
</rss>
