<?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>Developers, Developers, Developers! &#187; Haskell</title>
	<atom:link href="http://maksim.sorokin.dk/it/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://maksim.sorokin.dk/it</link>
	<description>Maksim Sorokin IT Blog</description>
	<lastBuildDate>Sun, 05 Feb 2012 19:37:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Memory Leak in Haskell During File Read 3</title>
		<link>http://maksim.sorokin.dk/it/2010/05/23/memory-leak-in-haskell-during-file-read-3/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/23/memory-leak-in-haskell-during-file-read-3/#comments</comments>
		<pubDate>Sun, 23 May 2010 05:13:47 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[success story]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=213</guid>
		<description><![CDATA[Problem described in previous two posts (1 2) has finally been fully understood and solved. Guys from #haskell channel on freenode IRC servers pointed me to the problem. The thing is that in the memory leak example I took length of read file and appended it to accumulator, which was sent further in the tail [...]]]></description>
			<content:encoded><![CDATA[<p>Problem described in previous two posts (<a href="http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/">1</a> <a href="http://maksim.sorokin.dk/it/2010/05/19/memory-leak-in-haskell-during-file-read-2/">2</a>) has finally been fully understood and solved. Guys from #haskell channel on <a href="http://freenode.net/irc_servers.shtml">freenode IRC servers</a> pointed me to the problem.</p>
<p>The thing is that <span id="more-213"></span>in the memory leak <a href="http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/">example</a> I took length of read file and appended it to accumulator, which was sent further in the tail call. And this accumulator was evaluated lazily! After adding <a href="http://users.aber.ac.uk/afc/stricthaskell.html#seq">strict sequencing operator</a>, the memory leak gone.</p>
<p>So instead of tail call:</p>
<pre class="brush: plain; title: ;">test fns $ acc + (B.length contents)</pre>
<p>I should have used:</p>
<pre class="brush: plain; title: ;">test fns $! acc + (B.length contents)</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/23/memory-leak-in-haskell-during-file-read-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Memory Leak in Haskell During File Read 2</title>
		<link>http://maksim.sorokin.dk/it/2010/05/19/memory-leak-in-haskell-during-file-read-2/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/19/memory-leak-in-haskell-during-file-read-2/#comments</comments>
		<pubDate>Wed, 19 May 2010 19:15:26 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[memory leak]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=193</guid>
		<description><![CDATA[UPD.: Issue has been resolved Things started to getting clearer. Here is a nice page explaining laziness during file read in Haskell (thanks to Vadim Platonov), section "hGetContents, hClose, readFile". I have tried samples from that resource which should solve unwanted laziness, but memory leak still occurred. Moreover, those samples ran for ages on just [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPD.:</strong> Issue has been <a href="http://maksim.sorokin.dk/it/2010/05/23/memory-leak-in-haskell-during-file-read-3/">resolved</a></p>
<p>Things started to getting clearer. <a href="http://users.aber.ac.uk/afc/stricthaskell.html#semiclosed">Here</a> is a nice page explaining laziness during file read in Haskell (thanks to <a href="http://lt.linkedin.com/pub/vadim-platonov/9/315/1b">Vadim Platonov</a>), section "hGetContents, hClose, readFile".<br />
I have tried samples from that resource which should solve unwanted laziness, but memory leak still occurred. Moreover, those samples ran for ages on just several thousands of files and ate much more memory comparing to standard <code>System.IO</code> functions.</p>
<p>But my colleague just informed me, that the version <a href="http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/">which I posted previously</a> runs without leaks on newer ghci version. I am too f*cked up after working day, so I hope to figure that out tomorrow.</p>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/19/memory-leak-in-haskell-during-file-read-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Memory Leak in Haskell During File Read</title>
		<link>http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/#comments</comments>
		<pubDate>Tue, 18 May 2010 20:31:38 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=184</guid>
		<description><![CDATA[UPD.: Issue has been resolved I used Haskell for doing certain operations on big set of XML files: parsing XML files, running regular expressions etc. Set is not that big, but still -- 90000 XML files totalling 2.7GB. I faced memory leaks in every program that I wrote. It was quite annoying since  Haskell was [...]]]></description>
			<content:encoded><![CDATA[<p><b>UPD.:</b> Issue has been <a href="http://maksim.sorokin.dk/it/2010/05/23/memory-leak-in-haskell-during-file-read-3/">resolved</a></p>
<p>I used Haskell for doing certain operations on big set of XML files: parsing XML files, running regular expressions etc. Set is not that big, but still -- 90000 XML files totalling 2.7GB.<br />
I faced memory leaks in every program that I wrote. It was quite annoying since <span id="more-184"></span> Haskell was chosen as primary language for the project and I needed to produce some results relatively fast.</p>
<p>Today I decided to take closer look during what stage leak occurred. My initial assumption about leak during file read was confirmed. Initially I used <a href="http://www.zvon.org/other/haskell/Outputprelude/readFile_f.html"><code>readFile</code> to read a file. But in this example I use </a><a href="http://www.haskell.org/ghc/docs/6.12.2/html/libraries/bytestring-0.9.1.6/Data-ByteString.html"><code>Data.ByteString</code></a> since it gracefully handles file close after opening.</p>
<p>Here is my example:</p>
<pre class="brush: plain; title: ;">
module SizeAnalyzer where

import Data.ByteString as B
import Utils

docsDir = &quot;/home/mah/Documents/university/MIPH/data/updatedXml&quot;

main =
   do filenames &lt;- getFilenamesInDirectory docsDir
      acc &lt;- test filenames 0
      return acc

test [] acc = return acc
test (fn:fns) acc =
   do contents &lt;- B.readFile (docsDir++&quot;/&quot;++fn)
      test fns $ acc + (B.length contents)
</pre>
<p>Memory usage slowly grows. Even if program is finished, used memory is not freed!</p>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/18/memory-leak-in-haskell-during-file-read/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Easy Way to Include a Module From Different Folder in Haskell</title>
		<link>http://maksim.sorokin.dk/it/2010/05/11/easy-way-to-include-a-module-from-different-folder-in-haskell/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/11/easy-way-to-include-a-module-from-different-folder-in-haskell/#comments</comments>
		<pubDate>Tue, 11 May 2010 19:29:58 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ghci]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=177</guid>
		<description><![CDATA[So you just want to include a module from a different folder in Haskell. Of course, you can easily make a cabal module, but sometimes you just need easy and fast (or maybe temporary) solution. During ghci startup just add -i&#60;dir&#62; parameter where &#60;dir&#62; stands for directory with module you want to import. For example [...]]]></description>
			<content:encoded><![CDATA[<p>So you just want to include a module from a different folder in Haskell. Of course, you can easily make a <a href="http://www.haskell.org/cabal/">cabal</a> module, but sometimes you just need easy and fast (or maybe temporary) solution.</p>
<p>During <a href="http://www.haskell.org/ghc/">ghci</a> startup just add <code>-i&lt;dir&gt;</code> parameter where <code>&lt;dir&gt;</code> stands for directory with module you want to import.<br />
For example if you want to include a module from parent directory:</p>
<pre>ghci -i../</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/11/easy-way-to-include-a-module-from-different-folder-in-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Config Files in Haskell</title>
		<link>http://maksim.sorokin.dk/it/2010/05/09/config-files-in-haskell/</link>
		<comments>http://maksim.sorokin.dk/it/2010/05/09/config-files-in-haskell/#comments</comments>
		<pubDate>Sun, 09 May 2010 08:09:41 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=170</guid>
		<description><![CDATA[Here is an easy and simple way to read configuration files in Haskell using ConfigFile package. Here is a simple configuration file test.cfg example: key: value And here is the program which reads the configuration file: import Data.ConfigFile import Data.Either.Utils main = do val &#60;- readfile emptyCP &#34;test.cfg&#34; let cp = forceEither val putStrLn $ [...]]]></description>
			<content:encoded><![CDATA[<p>Here is an easy and simple way to read configuration files in Haskell using <a href="http://hackage.haskell.org/package/ConfigFile">ConfigFile</a> package.<br />
<span id="more-170"></span></p>
<p>Here is a simple configuration file <code>test.cfg</code> example:</p>
<pre class="brush: plain; title: ;">
key: value
</pre>
<p>And here is the program which reads the configuration file:</p>
<pre class="brush: plain; title: ;">
import Data.ConfigFile
import Data.Either.Utils

main =
 do val &lt;- readfile emptyCP &quot;test.cfg&quot;
    let cp = forceEither val
    putStrLn $ forceEither $ get cp &quot;&quot; &quot;key&quot;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/05/09/config-files-in-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Haskell and MySQL</title>
		<link>http://maksim.sorokin.dk/it/2010/04/24/haskell-and-mysql/</link>
		<comments>http://maksim.sorokin.dk/it/2010/04/24/haskell-and-mysql/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 09:38:48 +0000</pubDate>
		<dc:creator>Maksim Sorokin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://maksim.sorokin.dk/it/?p=154</guid>
		<description><![CDATA[In this post I will describe how to connect and use MySQL with Haskell. In this example we will use Ubuntu machine. We will use MySQL driver for HDBC from HackageDB. First, we need to install MySQL server: sudo apt-get install mysql-server Then we need MySQL client library: sudo apt-get install libmysqlclient-dev Then, we install [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe how to connect and use MySQL with Haskell.<span id="more-154"></span></p>
<p>In this example we will use Ubuntu machine. We will use <a href="http://hackage.haskell.org/package/HDBC-mysql">MySQL driver for HDBC</a> from HackageDB.</p>
<p>First, we need to install MySQL server:</p>
<pre class="brush: plain; title: ;">sudo apt-get install mysql-server</pre>
<p>Then we need MySQL client library:</p>
<pre class="brush: plain; title: ;">sudo apt-get install libmysqlclient-dev</pre>
<p>Then, we install <a href="http://hackage.haskell.org/package/HDBC-mysql">HDBC MySQL driver</a> using <a href="http://www.haskell.org/cabal/">Cabal</a>:</p>
<pre class="brush: plain; title: ;">http://hackage.haskell.org/package/HDBC-mysql</pre>
<p>And you are ready to write some code!</p>
<pre class="brush: plain; title: ;">
module DatabaseTest where

import Database.HDBC
import Database.HDBC.MySQL

main =
   do conn &lt;- connectMySQL defaultMySQLConnectInfo {
                  mysqlHost = &quot;localhost&quot;,
                  mysqlDatabase = &quot;db&quot;,
                  mysqlUser = &quot;user&quot;,
                  mysqlPassword = &quot;pass&quot;,
                  mysqlUnixSocket = &quot;/var/run/mysqld/mysqld.sock&quot; }
      quickQuery conn &quot;INSERT INTO test VALUES (1)&quot; []
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maksim.sorokin.dk/it/2010/04/24/haskell-and-mysql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

