<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   
   xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    
    <title>nomeata’s mind shares - Haskell</title>
    <link>http://www.joachim-breitner.de/blog/</link>
    <description>Joachim Breitners Denkblogade</description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:mail@joachim-breitner.de" />
    <generator>Serendipity 1.7 - http://www.s9y.org/</generator>
    
    <image>
        <url>http://joachim-breitner.de/avatars/avatar_128.png</url>
        <title>RSS: nomeata’s mind shares - Haskell - Joachim Breitners Denkblogade</title>
        <link>http://www.joachim-breitner.de/blog/</link>
        <width>128</width>
        <height>128</height>
    </image>

<item>
    <title>The carbondioxide footprint of Debian's Haskell packages</title>
    <link>http://www.joachim-breitner.de/blog/archives/593-The-carbondioxide-footprint-of-Debians-Haskell-packages.html</link>
            <category>Debian</category>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/593-The-carbondioxide-footprint-of-Debians-Haskell-packages.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=593</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=593</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;
By now, Debian ships quite &lt;a href=&quot;http://qa.debian.org/developer.php?login=pkg-haskell-maintainers@lists.alioth.debian.org&quot;&gt;a lot of Haskell packages&lt;/a&gt; (~600). Because of GHC&#039;s ABI volatility, whenever we upload a new version of a library, we have to rebuild all libraries that depend on that. In particular, if we upload a new version of the compiler itself, we have to rebuild all Haskell library packages. So we have to rebuild stuff a lot. Luckily, Debian has a &lt;a href=&quot;https://buildd.debian.org/&quot;&gt;decent autobuilding setup&lt;/a&gt; so that I just need to tell it what to rebuild, and the rest happens automatically (including &lt;a href=&quot;http://upsilon.cc/~zack/blog/posts/2009/07/wanna-build_gains_detection_of_uninstallable_build-deps/&quot;&gt;figuring out the actual order to build things&lt;/a&gt;). &lt;br /&gt;&lt;/p&gt; 
&lt;p&gt;I was curious how much we use the buildd system compared to other packages, and also how long the builders are busy building Haskell packages. All the data is in a postgresql database on buildd.debian.org, so with some python and javascript code, I can visualize this. &lt;a href=&quot;https://buildd.debian.org/~nomeata/graphs.cgi&quot;&gt;The graphs&lt;/a&gt; show the number of all uploads by autobuilder on the amd64 architecture, with haskell uploads specially marked, and the second graph does the same for the build time. You can select time ranges and get aggregate statistics for that time span.&lt;/p&gt; 
&lt;p&gt;During the last four days a complete rebuild was happening, due to the upload of GHC 7.6.3. During these 2 days and 18 hours building 537 packages took 48 hours of build time and produced 15kg of CO&lt;sub&gt;2&lt;/sub&gt;. That is 94% of all uploads and 91% the total build time&lt;sub&gt;&lt;/sub&gt;. The numbers are lower for the whole of last year: 52% of uploads, 31% of build time and 57kg of CO&lt;sub&gt;2&lt;/sub&gt;. (The CO&lt;sub&gt;2&lt;/sub&gt; numbers are very rough estimates.)&lt;br /&gt;&lt;/p&gt; 
&lt;p&gt;Note that amd64 is a bit special, as most packages are uploaded on this architecture by the developers, so no automatic builds are happening. On other architectures have, every upload of a (arch:any) package is built, so the share of Haskell packages will be lower. Unfortunately, at the moment the database does not provide me with a table across all architectures (and I was too lazy to make it configurable yet).&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 24 Apr 2013 13:36:02 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/593-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F593-The-carbondioxide-footprint-of-Debians-Haskell-packages.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>Evaluation-State Assertions in Haskell</title>
    <link>http://www.joachim-breitner.de/blog/archives/590-Evaluation-State-Assertions-in-Haskell.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/590-Evaluation-State-Assertions-in-Haskell.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=590</wfw:comment>

    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=590</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;I have just uploaded a new version of &lt;a href=&quot;http://hackage.haskell.org/package/ghc-heap-view&quot;&gt;ghc-heap-view&lt;/a&gt; to Hackage that provides “Evaluation state assertions” in the module &lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-heap-view/0.4.2.0/doc/html/GHC-AssertNF.html&quot;&gt;&lt;tt&gt;GHC.AssertNF&lt;/tt&gt;&lt;/a&gt;.&lt;/p&gt; 
&lt;p&gt;Imagine you are writing a web application in Haskell that sports a global number-of-visitors counter in an &lt;tt&gt;&lt;a href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-IORef.html#t:IORef&quot;&gt;IORef&lt;/a&gt; Int&lt;/tt&gt;. For every request, you call &lt;tt&gt;&lt;a href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-IORef.html#v:modifyIORef&quot;&gt;modifyIORef&lt;/a&gt; (+1)&lt;/tt&gt;. Eventually, you notice your very popular web site to hog more and more memory. So you browse to the internal page that shows the counter, and you have to wait for a long time until you eventually see the result (or get a stack overflow). The reason: The applications of&amp;#160; &lt;tt&gt;(+1)&lt;/tt&gt; were not performed until you looked at the number; instead, a long chain of such computation first filled your heap and then your stack.&lt;/p&gt; 
&lt;p&gt;So you have learned the hard way that you might want to avoid space leaks, and want calculations to be done during the request that caused them, and want the &lt;tt&gt;IORef&lt;/tt&gt; to always contain fully evaluated data. So you stumble about &lt;a href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-IORef.html#v:modifyIORef-39-&quot;&gt;&lt;tt&gt;modifyIORef&#039;&lt;/tt&gt;&lt;/a&gt; in &lt;tt&gt;Data.IORef&lt;/tt&gt; and indeed, this fixes your problem.&lt;/p&gt; 
&lt;p&gt; Later, you notice that you want to count &lt;tt&gt;POST&lt;/tt&gt; and &lt;tt&gt;GET&lt;/tt&gt; requests separately. You change the type to &lt;tt&gt;IORef (Int, Int)&lt;/tt&gt; and call &lt;tt&gt;modifyIORef&#039; (&lt;a href=&quot;http://www.haskell.org/ghc/docs/latest/html/libraries/base//Control-Arrow.html#v:first&quot;&gt;first&lt;/a&gt; (+1))&lt;/tt&gt; or &lt;tt&gt;modifyIORef&#039; (&lt;a href=&quot;http://www.haskell.org/ghc/docs/latest/html/libraries/base//Control-Arrow.html#v:second&quot;&gt;second&lt;/a&gt; (+1))&lt;/tt&gt;. And suddenly, the space leak is back (which you only notice after the next push to the real site, because your local tests never caused enough requests to make it noticeable). So you not only want to fix it, you also want to ensure that it does not break again.&lt;/p&gt; 
&lt;p&gt;In other words, you want to ensure the policy that values stored in an &lt;tt&gt;IORef&lt;/tt&gt; are always in normal form. You achieve this with the following alternative to &lt;tt&gt;modifyIORef&#039;&lt;/tt&gt;:&lt;/p&gt; 
&lt;pre&gt;modifyIORef&#039;Assert :: IORef a -&amp;gt; (a -&amp;gt; a) -&amp;gt; IO ()
modifyIORef&#039;Assert ref f = do
    x &amp;lt;- readIORef ref
    let x&#039; = f x
    x&#039; `seq` return ()
    &lt;a title=&quot;&quot; target=&quot;&quot; href=&quot;http://hackage.haskell.org/packages/archive/ghc-heap-view/0.4.2.0/doc/html/GHC-AssertNF.html#v:assertNF&quot;&gt;assertNF&lt;/a&gt; x&#039;
    writeIORef ref x&#039;&lt;/pre&gt; 
&lt;p&gt;Using this instead of &lt;tt&gt;modifyIORef&#039;&lt;/tt&gt; will print this warning to standard error output right the first time you call &lt;tt&gt;modifyIORef&#039;Assert (first (+1))&lt;/tt&gt;:&lt;/p&gt; 
&lt;pre&gt;Parameter not in normal form: 2 thunks found:
let x1 = (S# 1,S# 1)
in _bh (_thunk x1 (_bco (S# 1)),_sel x1)
&lt;/pre&gt; 
&lt;p&gt;(Otherwise, the program runs as usual.) So obviously, you need to use a strict variant of &lt;tt&gt;first&lt;/tt&gt; (or &lt;a href=&quot;http://hackage.haskell.org/packages/archive/strict/0.3.2/doc/html/Data-Strict-Tuple.html&quot;&gt;strict pairs&lt;/a&gt;):&lt;/p&gt; 
&lt;pre&gt;first&#039; :: (a -&amp;gt; b) -&amp;gt; (a, c) -&amp;gt; (b, c)
first&#039; f (x,y) = let { x&#039; = f x; r = (x&#039;, y) } in x&#039; `seq` r `seq` r
&lt;/pre&gt; 
&lt;p&gt;With this, the warning goes away. Whenever you now change the type of the &lt;tt&gt;IORef&lt;/tt&gt; or modify it in a too-lazy-way, you can be sure that you’ll be warned about it, before the space leak itself becomes noticeable.&lt;/p&gt; 
&lt;p&gt;In the production code, you might want to disable the check. For that, simply put &lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-heap-view/0.4.2.0/doc/html/GHC-AssertNF.html#v:disableAssertNF&quot;&gt;&lt;tt&gt;disableAssertNF&lt;/tt&gt;&lt;/a&gt; somewhere in your main function.&lt;/p&gt; 
&lt;p&gt;Why is this better than just calling &lt;a href=&quot;http://hackage.haskell.org/packages/archive/deepseq/1.3.0.1/doc/html/Control-DeepSeq.html#v:deepseq&quot;&gt;&lt;tt&gt;deepseq&lt;/tt&gt;&lt;/a&gt; in &lt;tt&gt;modifyIORef&#039;Assert&lt;/tt&gt;? Because this way, the code still creates unwanted thunks that are then evaluated before storing them in the &lt;tt&gt;IORef&lt;/tt&gt;, whereas with &lt;tt&gt;assertNF&lt;/tt&gt; you are told about the thunks and can prevent them from being created in the first place. Also, &lt;tt&gt;assertNF&lt;/tt&gt; does not add a type class constraint.&lt;/p&gt; 
&lt;p&gt;This is just one example application for &lt;tt&gt;assertNF&lt;/tt&gt; (and its variants &lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-heap-view/0.4.2.0/doc/html/GHC-AssertNF.html#v:assertNFNamed&quot;&gt;&lt;tt&gt;assertNFNamed&lt;/tt&gt;&lt;/a&gt;, which includes a name in the warning to better spot the cause, and &lt;tt&gt;$&lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-heap-view/0.4.2.0/doc/html/GHC-AssertNF.html#v:assertNFHere&quot;&gt;assertNFHere&lt;/a&gt;&lt;/tt&gt;, which uses Template Haskell to include the current source code position in the warning), and I hope that there are more. If you happen to make use of it, I’d like to hear your story.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 06 Feb 2013 10:33:03 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/590-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F590-Evaluation-State-Assertions-in-Haskell.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>“Haskell Bytes” again</title>
    <link>http://www.joachim-breitner.de/blog/archives/584-Haskell-Bytes-again.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/584-Haskell-Bytes-again.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=584</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=584</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;&lt;a href=&quot;http://www.iai.uni-bonn.de/~jv/&quot;&gt;Janis Voigtländer&lt;/a&gt; has invited me again to give a lecture in his &lt;a href=&quot;http://www.iai.uni-bonn.de/~jv/teaching/ffp12/&quot;&gt;Advanced Functional Programming&lt;/a&gt; course at the University of Bonn. Like last time, when I talked about &lt;a href=&quot;http://www.joachim-breitner.de/blog/archives/539-Guest-lecture-on-Haskell-performance.html&quot;&gt;performance analysis in Haskell&lt;/a&gt;, I chose a topic that is more on implementationishy side to contrast the theoretic content of the rest of the course. I recycled &lt;a href=&quot;http://www.joachim-breitner.de/blog/archives/558-Haskell-Bytes.html&quot;&gt;my talk on the memory representation of GHC&lt;/a&gt; that I have held at last year’s &lt;a href=&quot;http://mrmcd.net/&quot;&gt;Meta Main-Rhein Chaos Days&lt;/a&gt;. As usual I provide a &lt;a href=&quot;http://www.joachim-breitner.de/publications/haskell_bytes_bonn_2013-01-10.pdf&quot;&gt;transcript of the talk&lt;/a&gt; as intended (not as held). It is slightly revised over the old version and I have added a section on unboxed values in constructors, which I have nevertheless skipped today.&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Thu, 10 Jan 2013 23:24:26 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/584-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F584-Haskell-Bytes-again.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>Circle Packing</title>
    <link>http://www.joachim-breitner.de/blog/archives/578-Circle-Packing.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/578-Circle-Packing.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=578</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=578</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;For an &lt;a href=&quot;http://www.meetup.com/The-Karlsruhe-Functional-Programmers-Meetup-Group/events/93934702/&quot;&gt;upcoming introductory Haskell talk&lt;/a&gt; of mine (next Tuesday in Karlsruhe – please come and join if you will) I was looking into data visualization as a example application. With libraries like &lt;a href=&quot;http://gloss.ouroborus.net/&quot;&gt;gloss&lt;/a&gt;, getting some nice vector graphics up and running within one talk is quite possible.&lt;/p&gt; 
&lt;p&gt;For some reason, I want to arrange multiple circles of varying size so that they do not overlap and use as little space as possible. My first approach was to use general purpose optimizers such as &lt;a href=&quot;http://hackage.haskell.org/package/cmaes&quot;&gt;cmaes&lt;/a&gt;, &lt;a href=&quot;http://hackage.haskell.org/packages/archive/hmatrix/latest/doc/html/Numeric-GSL-Minimization.html&quot;&gt;Numeric.GSL.Minimization&lt;/a&gt; from the &lt;a href=&quot;http://hackage.haskell.org/package/hmatrix&quot;&gt;hmatrix&lt;/a&gt; package and &lt;a href=&quot;http://hackage.haskell.org/package/force-layout&quot;&gt;force-layout&lt;/a&gt;. I especially liked the interface of cmaes, which is able to minimize a function of, say, type &lt;tt&gt;[(String, Double, Double)] -&amp;gt; Double&lt;/tt&gt; by automatically finding the values of type &lt;tt&gt;Double&lt;/tt&gt; in the input, as described by &lt;a href=&quot;http://www.haskell.org/pipermail/haskell-cafe/2012-October/103733.html&quot;&gt;Takayuki Muranushi&lt;/a&gt;. That would have looked great in the talk. Unfortunately, none of these libraries gave sufficient good results in a reasonable amount of time for this problem.&lt;/p&gt; 
&lt;p&gt;I then reviewed some of the academic literature on the circle packing problem and there were some algorithms proposed, but no simple one and none of the papers had a concise pseudo-code description that I could transfer to Haskell.&lt;/p&gt; 
&lt;p&gt;So eventually I set out to implement a relatively dump and slow greedy algorithm myself: I place one circle after another, starting with the largest, and among the valid positions where a new circle touches two already placed circles, I choose the positions closest to the center of mass. The result, available in &lt;a href=&quot;http://hackage.haskell.org/package/circle-packing&quot;&gt;the circle-packing package&lt;/a&gt;, looks surprisingly well, here visualized using the diagrams library (See the documentation of &lt;a href=&quot;http://hackage.haskell.org/packages/archive/circle-packing/latest/doc/html/Optimisation-CirclePacking.html&quot;&gt;Optimisation.CirclePacking&lt;/a&gt; for the code used to generate that image):&lt;/p&gt; 
&lt;div align=&quot;center&quot;&gt;&lt;img width=&quot;400&quot; height=&quot;400&quot; src=&quot;http://darcs.nomeata.de/circle-packing/example.svg&quot; /&gt;&lt;/div&gt; 
&lt;p&gt;Now showing just this image is not a very good way to demonstrate my code. A few years ago, I might have created a CGI script that would dynamically generate images based on your input. But not in 2012: Since &lt;a href=&quot;http://darcs.nomeata.de/circle-packing/Optimisation/CirclePacking.hs&quot;&gt;my code&lt;/a&gt; is pure Haskell without &lt;a href=&quot;https://github.com/faylang/fay/issues/98&quot;&gt;fancy features&lt;/a&gt; like type classes, I can use the &lt;a href=&quot;http://fay-lang.org/&quot;&gt;fay compiler&lt;/a&gt; to generate JavaScript code from it. Add a little &lt;a href=&quot;http://darcs.nomeata.de/circle-packing/fay/fay-demo.hs&quot;&gt;Haskell code to interact with the HTML5 canvas&lt;/a&gt; and now you can &lt;a href=&quot;http://darcs.nomeata.de/circle-packing/fay/fay-demo.html&quot;&gt;interactively try out circle-packing in your browser&lt;/a&gt;.&lt;/p&gt; 
&lt;p&gt;Oh, and while I am talking about neat tricks: You can put vector graphics in your haddock documentation, as I have done for Optimisation.CirclePacking, using the syntax &lt;tt&gt;&amp;lt;&amp;lt;&amp;lt;data:image/svg+xml;base64,PD94bWwgdmV...c3ZnPg==&amp;gt;&amp;gt;.&lt;/tt&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Sun, 16 Dec 2012 19:04:17 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/578-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F578-Circle-Packing.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>Calculating the internal rate of return with hledger</title>
    <link>http://www.joachim-breitner.de/blog/archives/573-Calculating-the-internal-rate-of-return-with-hledger.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/573-Calculating-the-internal-rate-of-return-with-hledger.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=573</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=573</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;For more than ten years now, I am a regular and happy user of &lt;a href=&quot;http://www.gnucash.org/&quot;&gt;GnuCash&lt;/a&gt;, the free accountancy program. Especially the integrated online banking support for &lt;a href=&quot;http://en.wikipedia.org/wiki/HBCI&quot;&gt;HBCI&lt;/a&gt; that allows me not only to fetch my transactions, but also to transfer money using a cryptographic makes it a great tool. Nevertheless, it has shortcomings, especially when it comes to reports. And for some reason I never felt the urge to hack on that C/Guile code (although I recently &lt;a href=&quot;https://bugzilla.gnome.org/show_bug.cgi?id=120854&quot;&gt;hacked a bit on the UI&lt;/a&gt;).&lt;br /&gt;&lt;/p&gt; 
&lt;p&gt;&lt;a href=&quot;http://joeyh.name/blog/entry/hledger/&quot;&gt;Joey Hess’ blog post&lt;/a&gt; about Simon
Michael’s &lt;a href=&quot;http://hledger.org/&quot;&gt;hledger&lt;/a&gt; made me look at that command line based accountancy tool. It certainly won’t replace Gnucash for me, but luckily &lt;a href=&quot;http://ledger-cli.org/&quot;&gt;ledger&lt;/a&gt;, of which hledger is a re-implementation, can read GnuCash’s file format and convert it to a ledger file that hledger can read as well. So now I can do analysis on my financial data in Haskell – what would you want more?&lt;/p&gt; 
&lt;p&gt;One report that I was missing was the &lt;a href=&quot;http://en.wikipedia.org/wiki/Internal_rate_of_return&quot;&gt;&lt;em&gt;internal rate of investment&lt;/em&gt;&lt;/a&gt; of some account. This is the annual rate of a hypothetical fixed interest-bearing savings account that would, given the same deposits and payouts, result in the same final value. I now implemented this as the &lt;a href=&quot;http://hackage.haskell.org/package/hledger-irr&quot;&gt;hledger-irr&lt;/a&gt; command and – as you would expect – you can find it on hackage. See the package description for documentation and example output.&lt;/p&gt; 
&lt;p&gt;It is very fresh, hardly tested code, so don’t base important decisions on it yet. Also, it needs work to work correctly with multiple currencies or things with varying prices, and I am not yet sure what to do there.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Simon asked me to elaborate the difference to &lt;a href=&quot;http://hackage.haskell.org/package/hledger-interest&quot;&gt;hledger-interest&lt;/a&gt; by Peter Simons (on which my code was initial based, but eventually I rewrote everything but the option parsing code). The difference is that hledger-interest answers the question „I have this investment with this yearly interest rate (which may even change), how large are the interest payments going to be.“ I imagine a usecase is that you have borrowed some money to a friend at a certain (surely amicable) rate and need to figure out what he owes you, even when you gave him the money mid year and he payed you some back shortly after easter. hledger-irr serves a different purpose: Here you already know your investment payments, gains and losses and you want to have a number describing “how good” your investment was. One usecase might be that, at the end of a live of paying into a pension fund, you ask yourself: “Given all the feeds and commissions, was this a good idea or should I just have invested the money myself?” Then the internal rate of investment tells you how lucrative an alternative fixed-rate investment would have had to been to match your pension fund investment. (Or course this is not the only aspect that you should look at when comparing investments, as it totally ignores risk and possible insurance elements of the investment.)&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Fri, 07 Dec 2012 23:22:41 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/573-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F573-Calculating-the-internal-rate-of-return-with-hledger.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>c't features Haskell</title>
    <link>http://www.joachim-breitner.de/blog/archives/566-ct-features-Haskell.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/566-ct-features-Haskell.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=566</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=566</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;
This week’s issue of &lt;a href=&quot;http://www.heise.de/ct/&quot;&gt;c&#039;t&lt;/a&gt;, one of Germany’s largest and most influential computer magazine, has a six page introductory &lt;a href=&quot;http://www.heise.de/ct/inhalt/2012/23/182/&quot;&gt;article about Haskell&lt;/a&gt; (c&#039;t 2012, Issue 23, pages 182-187). The author Harad Bögeholz demonstrates its features and strength by implementing a &lt;a href=&quot;http://en.wikipedia.org/wiki/Slitherlink&quot;&gt;Slitherlink&lt;/a&gt; puzzle solver. As I have helped him a bit by checking the code and article for untypical Haskell code and general advice, I happen to be named at the end of the article – nice. &lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 24 Oct 2012 20:49:20 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/566-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F566-ct-features-Haskell.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>Dennis Felsing’s thesis on ghc-vis submitted</title>
    <link>http://www.joachim-breitner.de/blog/archives/562-Dennis-Felsings-thesis-on-ghc-vis-submitted.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/562-Dennis-Felsings-thesis-on-ghc-vis-submitted.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=562</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=562</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;Last week, my first student ever submitted his bachelor thesis „&lt;a href=&quot;http://felsin9.de/nnis/ghc-vis/thesis/&quot;&gt;Visualization of Lazy Evaluation and Sharing&lt;/a&gt;“ about a tool he created that allows you to investigate the heap of a running Haskell program, including unevaluated values and their sharing properties, in a visual and interactive manner. You can see it in action at the end of the&amp;#160; &lt;a href=&quot;http://www.youtube.com/watch?v=DGsVX7Qqv-0&quot;&gt;video of my lightning talk&lt;/a&gt; about &lt;a href=&quot;http://arxiv.org/abs/1207.2017&quot;&gt;ghc-dup&lt;/a&gt; at the &lt;a href=&quot;http://www.haskell.org/haskellwiki/HaskellImplementorsWorkshop/2012&quot;&gt;Haskell Implementors Workshop&lt;/a&gt; this year, and read more about it on Dennis’ &lt;a href=&quot;http://felsin9.de/nnis/ghc-vis/&quot;&gt;ghc-vis&lt;/a&gt; web page. I’m quite happy about the result and I think I can get used to have other people implement my ideas and needs :-)&lt;/p&gt;
&lt;p&gt;Dennis said he is willing to continue the maintenance of the tool, so give it a shot and bombard him with bug reports and feature requests!&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 02 Oct 2012 09:39:01 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/562-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F562-Dennis-Felsings-thesis-on-ghc-vis-submitted.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>The might applicative left fold</title>
    <link>http://www.joachim-breitner.de/blog/archives/560-The-might-applicative-left-fold.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/560-The-might-applicative-left-fold.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=560</wfw:comment>

    <slash:comments>6</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=560</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;Just about three years ago, I created the “&lt;a href=&quot;http://darcs.nomeata.de/arbtt/doc/users_guide/&quot;&gt;automatic rule-based time 
tracker&lt;/a&gt;” (arbtt), a tool that quietly runs in the background, records 
your current windows and their titles, and allows you to later process 
this data using, well, rules. By now, I have almost half a million 
records, spanning 317 days of me working at the computer. Processing 
this amount of data has become very memory-hungry: It takes 1G of RAM to
 process my data. Other users, with a presumably higher sampling rate, 
report even worse performance, which finally made me approach the problem again.&lt;/p&gt; 
&lt;p&gt;Naturally, one wonders why it is such a memory hog, after all it 
takes just one run over the data to produce a report. The data itself is
 a lazy list so the garbage collector should the be able to drop the 
seen elements immediately.&lt;/p&gt; 
&lt;p&gt;But arbtt is able to print several reports in one run; there is even 
an option (&lt;a href=&quot;http://darcs.nomeata.de/arbtt/doc/users_guide/arbtt-stats.html#id3116568&quot;&gt;&lt;tt&gt;--each-category&lt;/tt&gt;&lt;/a&gt;) that creates a number of reports based on 
the data itself. The code was structured that first a number of values 
that are possibly used by several reports are first created one and then
 re-used by the reports. And then there is the issue of the filters: The
 user specifies a what predicates are interesting (e.g., those where he 
was active) and some reports need to know not only which samples were 
matched, but also distinguish the consecutive runs of selected samples.&lt;/p&gt; 
&lt;p&gt;Lots of reasons that made it hard to not use the list of of samples 
several times, which causes it to be completely retained in memory. The 
idea of completely rewriting everything in a much more imperative way 
was not appealing. But luckily Haskell’s good abstraction possibilities can help here.&lt;/p&gt; 
&lt;p&gt;What is the “correct” way to traverse a lazy list and calculate some information about it? It is a strict left fold, i.e. an algorithm that can be represented as arguments to&lt;/p&gt; 
&lt;pre&gt;&lt;a title=&quot;&quot; target=&quot;&quot; href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-List.html#v:foldl-39-&quot;&gt;foldl&#039;&lt;/a&gt; :: (s -&amp;gt; x -&amp;gt; s) -&amp;gt; s -&amp;gt; [x] -&amp;gt; s&lt;/pre&gt; 
&lt;p&gt; For those who are new to folds: The first argument is a function that processes one element from the list, returning the new state of the processing. The second argument is the initial state. And &lt;tt&gt;foldl&#039;&lt;/tt&gt; can apply such an algorithm to a list to return a final state.&lt;/p&gt; 
&lt;p&gt;So obviously I had to express my reports as left folds. To think clearer about it, I gave them a name. I also added a finishing step to the mix, which is handy:&lt;/p&gt; 
&lt;pre&gt;data LeftFold x a = forall s. LeftFold {
&amp;#160;&amp;#160;&amp;#160; start :: s,
&amp;#160;&amp;#160;&amp;#160; process :: s -&amp;gt; x -&amp;gt; s,
&amp;#160;&amp;#160;&amp;#160; finish :: s -&amp;gt; a
&amp;#160;&amp;#160;&amp;#160; }
&lt;/pre&gt; 
&lt;p&gt;A value of type &lt;tt&gt;LeftFold x a&lt;/tt&gt; is then an algorithm that traverses a list of &lt;tt&gt;x&lt;/tt&gt;es and returns something of type &lt;tt&gt;a&lt;/tt&gt;. The &lt;tt&gt;forall s.&lt;/tt&gt; means that the user of such a processor must not make any assumptions about the type of the state. I also have a function that runs such a list processor, simply by invoking &lt;tt&gt;foldl&#039;&lt;/tt&gt; with the arguments stored in the &lt;tt&gt;LeftFold&lt;/tt&gt; constructor:&lt;/p&gt; 
&lt;pre&gt;runLeftFold :: LeftFold x a -&amp;gt; [x] -&amp;gt; a&lt;br /&gt;runLeftFold (LeftFold st1 p1 f1) xs = f1 (foldl&#039; p1 st1 xs)&lt;/pre&gt; 
&lt;p&gt;Now, as a Haskell programmer, I am searching for monads everywhere, and it really would have been nice if this were a monad, as they are very easy to compose. But unfortunately, they do not form a monad. If they did then I could decide after running one processor and looking at the result how I would want to process the list now, but this obviously contradicts with the desire to traverse the list only once.&lt;/p&gt; 
&lt;p&gt;But there is the monad’s smaller ugly sibling, the applicative functor. One can still somewhat nicely compose them to form more complex algorithms, just with more restrictions. Here is my instance:&lt;/p&gt; 
&lt;pre&gt;instance Functor (LeftFold x) where
&amp;#160;&amp;#160;&amp;#160; fmap f (LeftFold st1 p1 f2) = LeftFold st1 p1 (f . f2)

instance Applicative (LeftFold x) where
&amp;#160;&amp;#160;&amp;#160; pure x = LeftFold () const (const x)
&amp;#160;&amp;#160;&amp;#160; LeftFold st1 p1 f1 &amp;lt;*&amp;gt; LeftFold st2 p2 f2 = LeftFold {
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; start&amp;#160;&amp;#160; =&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; st1 :!: st2,
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; process = \(s1 :!: s2) x -&amp;gt; p1 s1 x :!: p2 s2 x,
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; finish&amp;#160; = \(s1 :!: s2)&amp;#160;&amp;#160; -&amp;gt; f1 s1 (f2 s2)
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/pre&gt; 
&lt;p&gt;The &lt;tt&gt;:!:&lt;/tt&gt; operator is a &lt;a href=&quot;http://hackage.haskell.org/packages/archive/strict/latest/doc/html/Data-Strict-Tuple.html#v::-33-:&quot;&gt;strict tuple constructor&lt;/a&gt;. This is important, as otherwise the fold would be come a lazy one, I would be building up huge numbers of thunks and performance would be very bad. For the same reason every list processor should make sure that its state does not build thunks once it is in weak head normal form.&lt;/p&gt; 
&lt;p&gt;Now I am at a abstraction level that I feel comfortable working in, by writing functions that combine the list processors in various ways. Probably the most important one for me is already present in the libraries (here with a specialized type):&lt;br /&gt;&lt;/p&gt; 
&lt;pre&gt;&lt;a title=&quot;&quot; target=&quot;&quot; href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Traversable.html#v:sequenceA&quot;&gt;sequenceA&lt;/a&gt; :: [LeftFold x a] -&amp;gt; LeftFold x [a]&lt;/pre&gt; 
&lt;p&gt;This is the whole trick: Now I can, based on the user input, run any number and selection of reports in one single list traversal. I find it very elegant that “under the hood”, the strict tuples are nested at precisely the right depth depending on the length of the list.&lt;/p&gt; 
&lt;p&gt;As hinted at before, I do some interesting stuff that was previously represented as lists of lists of values. Expressing these as left folds was a bit tricky, but again, the complexity is contained in the combinators that I wrote (although it still gets confusing, check out &lt;a href=&quot;http://darcs.nomeata.de/arbtt/src/Stats.hs&quot;&gt;&lt;tt&gt;processIntervalReport&lt;/tt&gt; in &lt;tt&gt;Stats.hs&lt;/tt&gt;&lt;/a&gt;):&lt;/p&gt; 
&lt;pre&gt;monoidFold :: Monoid m =&amp;gt; LeftFold m m
mapElems :: LeftFold y a -&amp;gt; (x -&amp;gt; y) -&amp;gt; LeftFold x a 
filterWith :: (x -&amp;gt; Bool) -&amp;gt; LeftFold (Bool :!: x) a -&amp;gt; LeftFold x a
onSelected :: LeftFold x a -&amp;gt; LeftFold (Bool :!: x) a
onJusts :: LeftFold x a -&amp;gt; LeftFold (Maybe x) a
onAll :: LeftFold x a -&amp;gt; LeftFold (Bool :!: x) a
runOnGroups :: (x -&amp;gt; x -&amp;gt; Bool) -&amp;gt; LeftFold x y -&amp;gt; LeftFold y z -&amp;gt; LeftFold x z
runOnIntervals :: LeftFold x y -&amp;gt; LeftFold y z -&amp;gt; LeftFold (Bool :!: x) z
lfLength :: LeftFold x Int
lfFirst :: LeftFold x (Maybe x)
lfLast :: LeftFold x (Maybe x)
toList :: LeftFold x [x]
concatFold :: LeftFold [x] [x]&lt;/pre&gt; 
&lt;p&gt;As a result, the program now only requires 10MB and runs 18% faster.&lt;/p&gt; 
&lt;p&gt;If you wonder why, in the definition of &lt;tt&gt;runLeftFold&lt;/tt&gt;, I do not apply the finish function strictly: That is intentional; I am actually passing the result of a processor that calculates some often required data (e.g. total time recorded) as an argument to all the list processors. (Near the end of the main function in &lt;a href=&quot;http://darcs.nomeata.de/arbtt/src/stats-main.hs&quot;&gt;&lt;tt&gt;stats-main.hs&lt;/tt&gt;&lt;/a&gt;) This “loop” works fine as long as I am using these only in the &lt;tt&gt;finish&lt;/tt&gt; functions.&lt;br /&gt;&lt;/p&gt; 
&lt;p&gt;There is one downside to this approach: I cannot easily calculate stuff on demand &lt;em&gt;and&lt;/em&gt; share it between two reports. Previously, I could just bind this to a variable, pass it to all reports, only if at least one is interested it would be evaluated and if several are interested, the result would be shared. I do not have a good solution for this yet.&lt;/p&gt; 
&lt;p&gt;The code above is in the self-contained module &lt;a href=&quot;http://darcs.nomeata.de/arbtt/src/LeftFold.hs&quot;&gt;&lt;tt&gt;LeftFold.hs&lt;/tt&gt;&lt;/a&gt; in the arbtt sources.&lt;br /&gt;&lt;/p&gt; 
&lt;p&gt;Several People have had this idea before, here is &lt;a href=&quot;http://squing.blogspot.de/2008/11/beautiful-folding.html&quot;&gt;one blog post by Max Rabkin&lt;/a&gt;.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Fri, 28 Sep 2012 18:40:00 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/560-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F560-The-might-applicative-left-fold.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>“Haskell Bytes”</title>
    <link>http://www.joachim-breitner.de/blog/archives/558-Haskell-Bytes.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/558-Haskell-Bytes.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=558</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=558</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;Last Saturday I have held a talk at the &lt;a href=&quot;http://mrmcd.net/&quot;&gt;Meta Main-Rhein Chaosdays&lt;/a&gt; 2012 in Darmstadt, an event of the local Chaos Computer Club groups and not unsimilar to Karlsruhe’s yearly &lt;a href=&quot;http://gulas.ch/&quot;&gt;GPN&lt;/a&gt;. I was asked to give an talk on a advanced, Haskell related topic, so I took my audience on a &lt;a href=&quot;https://frab.mrmcd.net/mrmcd12/public/events/46&quot;&gt;guided tour through the memory of a running Haskell program&lt;/a&gt;, explained the different types of closures and their layout, and showed how info tables are used to allow the garbage collector to uniformly treat the objects. We also used that knowledge to roughly predict the memory footprint of a program processing a large file using the String data type.&lt;/p&gt; 
&lt;p&gt;Besides showing raw bytes (using my &lt;a href=&quot;http://hackage.haskell.org/package/ghc-heap-view&quot;&gt;ghc-heap-view&lt;/a&gt; package and a &lt;a href=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/Utils.hs&quot;&gt;small utility function&lt;/a&gt;) I included two visualizations:  One is the video of a copying garbage collector at work &lt;a href=&quot;http://www.joachim-breitner.de/blog/archives/557-A-copying-garbage-collector-animated.html&quot;&gt;that I blogged about last week&lt;/a&gt;, and the other is a nice tool that a student of mine creates for his bachelor thesis: It allows you to visualize the heap structure of a (potentially partially evaluated) value from GHCi and interactively evaluate parts of the structure – if you want, even thunks that are “hidden” behind other thunks, something that you cannot do from Haskell code. The following picture is a screen shot of ghc-vis visualizing the evaluation of the famous &lt;a href=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/Sieve.hs&quot;&gt;two-line primes definition&lt;/a&gt;:&lt;/p&gt; 
&lt;div align=&quot;center&quot;&gt;&lt;img height=&quot;1054&quot; width=&quot;443&quot; alt=&quot;ghc-vis at work&quot; src=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/vis-output-sieve.png&quot; /&gt;&lt;/div&gt; 
&lt;p&gt;The &lt;a href=&quot;https://frab.mrmcd.net/system/attachments/5/original/HaskellBytesSlides.pdf&quot;&gt;slides of my talk&lt;/a&gt; do not cover everything that was included, but &lt;a href=&quot;https://frab.mrmcd.net/system/attachments/4/original/HaskellBytes.pdf&quot;&gt;the transcript&lt;/a&gt; does. It is in German, so &lt;a href=&quot;http://www.joachim-breitner.de/blog/archives/539-Guest-lecture-on-Haskell-performance.html&quot;&gt;as before&lt;/a&gt;, if you want me to translate it, then (convince your professor or employer to) invite me to hold the talk again. The &lt;a href=&quot;http://hackage.haskell.org/package/ghc-vis&quot;&gt;ghc-vis&lt;/a&gt; tool can be found on Hackage, more information about it is &lt;a href=&quot;http://felsin9.de/nnis/ghc-vis&quot;&gt;on the author’s website&lt;/a&gt;.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Wed, 12 Sep 2012 21:53:08 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/558-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F558-Haskell-Bytes.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>A copying garbage collector animated</title>
    <link>http://www.joachim-breitner.de/blog/archives/557-A-copying-garbage-collector-animated.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/557-A-copying-garbage-collector-animated.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=557</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=557</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;Next weekend I will hold an advanced Haskell talk at the &lt;a href=&quot;http://mrmcd.net/&quot;&gt;Meta Rhein-Main ChaosDays&lt;/a&gt; in Darmstadt. It will mostly be a guided tour through the main memory of a running Haskell program, showing how things are represented and how they change over time. For this I cannot avoid to touch the issue of garbage collection, so I created a short animation:&lt;/p&gt; 
&lt;div align=&quot;center&quot;&gt;&lt;video height=&quot;500&quot; width=&quot;800&quot; controls=&quot;true&quot; poster=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/GC.png&quot; src=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/GC.webm&quot; align=&quot;center&quot; tabindex=&quot;0&quot;&gt;
Your browser does not seem to support WebM videos. Try the YouTube link below.
&lt;/video&gt;&lt;/div&gt; 
&lt;p&gt;(If you do not see it above, then you can try on &lt;a href=&quot;http://www.youtube.com/watch?v=PamW_iePSGU&quot;&gt;YouTube&lt;/a&gt;.)&lt;/p&gt; 
&lt;p&gt;It is created with &lt;a href=&quot;http://www.synfig.org/&quot;&gt;Synfig&lt;/a&gt;, feel free to use the &lt;a href=&quot;http://darcs.nomeata.de/talk-mrmcd12-haskell-bytes/GC.sifz&quot;&gt;sources&lt;/a&gt;. It seems that Synfig, although it has some features that allow you to link position in various objects, or calculate with them, is not really meant for programmers. Take the arrows: They are all quite similar, and defined by starting point, end point, and how much the initial segment sticks out to the right. I could even create them so that when I move the first or last point, the rest adjusts automatically. So one would expect that I can combine these shapes in one re-usable object that has these three values as parameters, but unfortunately, that is not the case. I guess next time I want to animate something as structured as this, I use either &lt;a href=&quot;http://en.wikipedia.org/wiki/PGF/TikZ&quot;&gt;tikz&lt;/a&gt; (and generate one page per frame, convert them to an image and then to a video) or a Haskell library like &lt;a href=&quot;http://gloss.ouroborus.net/&quot;&gt;gloss&lt;/a&gt; or &lt;a href=&quot;http://projects.haskell.org/diagrams/&quot;&gt;diagrams&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; I made some minor improvements to the video. Youtube does not allow me to change the video, so you’ll see the new version only here.&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Mon, 03 Sep 2012 15:00:22 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/557-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F557-A-copying-garbage-collector-animated.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>ghc-heap-view: Complete referential opacity</title>
    <link>http://www.joachim-breitner.de/blog/archives/548-ghc-heap-view-Complete-referential-opacity.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/548-ghc-heap-view-Complete-referential-opacity.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=548</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=548</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;During the last week, I created &lt;a href=&quot;http://hackage.haskell.org/package/ghc-heap-view&quot;&gt;ghc-heap-view&lt;/a&gt;, a library to investigate the actual memory representation of Haskell values. It is inspired by &lt;a href=&quot;http://hackage.haskell.org/package/vacuum&quot;&gt;vacuum&lt;/a&gt; and the &lt;a href=&quot;http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-debugger.html&quot;&gt;GHCi debugger&lt;/a&gt;, but goes beyond them by allowing the user to look inside thunks and functions and see what other values they refer to. Let me demonstrate it by running the &lt;a href=&quot;http://darcs.nomeata.de/ghc-heap-view/Demo.hs&quot;&gt;included demo&lt;/a&gt;:&lt;/p&gt; 
&lt;p&gt; &lt;/p&gt; 
&lt;h3&gt;ghc-heap-view-demo&lt;/h3&gt; 
&lt;p&gt;Here are a four different lists, where the first three are already evaluated.&lt;br /&gt;The first one, &lt;tt&gt;l&lt;/tt&gt;, was defined as a top level constant as&lt;/p&gt; 
&lt;pre&gt;&amp;gt; l = [1,2,3]&lt;/pre&gt; 
&lt;p&gt;and is now found at 0x00000000006d1750/2 (where the /2 is the pointer tag information) and fully evaluated:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ConsClosure {info = StgInfoTable {ptrs = 2, nptrs = 0, tipe = CONSTR_STATIC, srtlen = 1}, 
                 ptrArgs = [0x00000000006d16e0/1,0x00000000006d1730/2],
                 dataArgs = [], descr = &quot;ghc-prim:GHC.Types.:&quot;}&lt;/pre&gt; 
&lt;p&gt;The second one, &lt;tt&gt;l2&lt;/tt&gt;, is locally defined&lt;/p&gt; 
&lt;pre&gt;&amp;gt; let l2 = 4:l&lt;/pre&gt; 
&lt;p&gt;and now found at 0x00007fdce19fe4b0/2. See how the cons-cell references &lt;tt&gt;l&lt;/tt&gt;!&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ConsClosure {info = StgInfoTable {ptrs = 2, nptrs = 0, tipe = CONSTR_2_0, srtlen = 1},
                 ptrArgs = [0x00000000006dca50/1,0x00000000006d1750/2],
                 dataArgs = [],
                 descr = &quot;ghc-prim:GHC.Types.:&quot;}&lt;/pre&gt; 
&lt;p&gt;And the binding&lt;/p&gt; 
&lt;pre&gt;&amp;gt; args &amp;lt;- map length `fmap` getArgs&lt;/pre&gt; 
&lt;p&gt;evaluates to the “one”, global empty list at 0x00000000006db640/1:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ConsClosure {info = StgInfoTable {ptrs = 0, nptrs = 0, tipe = CONSTR_NOCAF_STATIC, srtlen = 0},
                 ptrArgs = [],
                 dataArgs = [],
                 descr = &quot;ghc-prim:GHC.Types.[]&quot;}&lt;/pre&gt; 
&lt;p&gt;And now we have, at 0x00007fdce19fe4c8, the concatenation of them, but unevaluated:&lt;/p&gt; 
&lt;pre&gt;&amp;gt; let x = l ++ l2 ++ args&lt;/pre&gt; 
&lt;p&gt;The thunk keeps a reference to &lt;tt&gt;l2&lt;/tt&gt; and &lt;tt&gt;args&lt;/tt&gt;, but not &lt;tt&gt;l&lt;/tt&gt;, as that is at a static address, unless you are running this in GHCi:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ThunkClosure {info = StgInfoTable {ptrs = 2, nptrs = 0, tipe = THUNK_2_0, srtlen = 1},
                  ptrArgs = [0x00007fdce19fe4b0/2,0x00000000006db640/1],
                  dataArgs = []}&lt;/pre&gt; 
&lt;p&gt;Now to some more closure types. &lt;tt&gt;m&lt;/tt&gt; and &lt;tt&gt;m&#039;&lt;/tt&gt; locally bound of type the unboxed type &lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0/doc/html/GHC-Prim.html#3&quot;&gt;&lt;tt&gt;Int#&lt;/tt&gt;&lt;/a&gt;, with values 42 resp. 23.&lt;/p&gt; 
&lt;pre&gt;&amp;gt; let f = \x n -&amp;gt; take (I# m + I# x) n ++ args
&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; t = f m&#039; l2&lt;/pre&gt; 
&lt;p&gt;So here is (0x00007fdce1937d50/2), referencing its free variables &lt;tt&gt;args&lt;/tt&gt; and 42:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; FunClosure {info = StgInfoTable {ptrs = 1, nptrs = 1, tipe = FUN_1_1, srtlen = 65553},
                ptrArgs = [0x00000000006db640/1],
                dataArgs = [42]}&lt;/pre&gt; 
&lt;p&gt;And &lt;tt&gt;t&lt;/tt&gt; is a thunk that applies &lt;tt&gt;f &lt;/tt&gt;(also referenced here) to an unboxed value (23) and &lt;tt&gt;l2&lt;/tt&gt;:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ThunkClosure {info = StgInfoTable {ptrs = 2, nptrs = 1, tipe = THUNK, srtlen = 0},
                  ptrArgs = [0x00007fdce19fe4b0/2,0x00007fdce1937d50/2],
                  dataArgs = [23]}&lt;/pre&gt; 
&lt;p&gt;Lastly, here is the standard example for self reference:&lt;/p&gt; 
&lt;pre&gt;&amp;gt; let x = id (:) () x&lt;/pre&gt; 
&lt;p&gt;This is what &lt;tt&gt;x&lt;/tt&gt; (0x00007fdce1947940) looks like, at least without -O:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ThunkClosure {info = StgInfoTable {ptrs = 0, nptrs = 0, tipe = THUNK, srtlen = 1},
                  ptrArgs = [],
                  dataArgs = []}&lt;/pre&gt; 
&lt;p&gt;So it is unevaluated. Let us evaluate it using &lt;tt&gt;seq&lt;/tt&gt;. Now we have, still at 0x00007fdce1947940:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; IndClosure {info = StgInfoTable {ptrs = 1, nptrs = 0, tipe = BLACKHOLE, srtlen = 0},
                indirectee = 0x00007fdce194cc98/2}&lt;/pre&gt; 
&lt;p&gt;The thunk was replaced by an indirection. If we look at the target, 0x00007fdce194cc98/2, we see that it is a newly created cons-cell referencing the original location of &lt;tt&gt;x&lt;/tt&gt;:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ConsClosure {info = StgInfoTable {ptrs = 2, nptrs = 0, tipe = CONSTR_2_0, srtlen = 1},
                 ptrArgs = [0x00000000006db620/1,0x00007fdce1947940],
                 dataArgs = [],
                 descr = &quot;ghc-prim:GHC.Types.:&quot;}&lt;/pre&gt; 
&lt;p&gt;After running the garbage collector (&lt;a href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-Mem.html#v:performGC&quot;&gt;&lt;tt&gt;performGC&lt;/tt&gt;&lt;/a&gt;), we find that the address of &lt;tt&gt;x&lt;/tt&gt; is now 0x00007fdce19f30d0/2 and that the self-reference is without indirections:&lt;/p&gt; 
&lt;pre&gt;&amp;#160;&amp;#160;&amp;#160; ConsClosure {info = StgInfoTable {ptrs = 2, nptrs = 0, tipe = CONSTR_2_0, srtlen = 1},
                 ptrArgs = [0x00000000006db620/1,0x00007fdce19f30d0/2],
                 dataArgs = [],
                 descr = &quot;ghc-prim:GHC.Types.:&quot;}&lt;/pre&gt; 
&lt;h3&gt;Future plans&lt;/h3&gt; 
&lt;p&gt;The output of ghc-heap-view is not really pretty yet; even the indentation in this blog post was added manually by me, so this really needs a pretty printer providing a nicer, possibly more compact representation, including something like what vacuum provides. Maybe vacuum can be ported to use this library, and also include the thunk’s and function’s references in the output. Maybe also the GHCi debugger can be extended to show more information about unevaluated expressions using this. Internally, the library is not very polished yet either. It only handles those closures types that I have seen so far, and is likely to break horribly if run in a threaded or debugging enabled runtime.&lt;/p&gt; 
&lt;h3&gt;How it works&lt;/h3&gt; 
&lt;p&gt;Obviously, this is not standard Haskell 98 code, but rather deep trickery involving the GHC API and some C code. Initially I tried to use the API that vacuum and the GHCi debugger rely on, which is an operation&lt;/p&gt; 
&lt;pre&gt;&lt;a title=&quot;&quot; target=&quot;&quot; href=&quot;http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0/doc/html/GHC-Prim.html#v%3AunpackClosure%23&quot;&gt;unpackClosure#&lt;/a&gt; :: a -&amp;gt; (# Addr#, Array# b, ByteArray# #)&lt;/pre&gt; 
&lt;p&gt;which takes any Haskell value and returns the address to its info table, the pointers and the non-pointer-data in the closure. Unfortunately, it was not complete in that it was meant only for data closures and will for other closure types, e.g. thunks, return no data and no pointers (as can be seen &lt;a href=&quot;http://hackage.haskell.org/trac/ghc/browser/rts/PrimOps.cmm?rev=c6a2bbdbd3d701653d7e2ee22e2dea73316b49d8#L1680&quot;&gt;in the code&lt;/a&gt;). So I implemented my own version of this operation:&lt;/p&gt; 
&lt;pre&gt;foreign import prim &quot;slurpClosurezh&quot; slurpClosure# :: Any -&amp;gt; (# Addr#, ByteArray#, Array# b #)&lt;/pre&gt; 
&lt;p&gt;where the returned &lt;tt&gt;ByteArray#&lt;/tt&gt; contains the &lt;em&gt;complete&lt;/em&gt; closure, including extra information fields such as the arity of a function. The &lt;tt&gt;Array#&lt;/tt&gt; is again the list of pointers in the closure. At first glance, this is a duplication, as the pointers are of course also contained in the &lt;tt&gt;ByteArray#&lt;/tt&gt;. But as soon as the GHC runtime reigns again, a garbage collector run can happen, the referenced values will move somewhere else, and the words that once were pointers in the &lt;tt&gt;ByteArray#&lt;/tt&gt; become useless. But the corresponding entries in the &lt;tt&gt;Array#&lt;/tt&gt; are updated by the garbage collector, as it knows that these are pointers, and not just words. This way, we get both a faithful copy of the closure on the heap and useful references to the contained data. Here is a demonstration of this effect: &lt;br /&gt;&lt;/p&gt; 
&lt;pre&gt;$ ghci -XMagicHash -package ghc-heap-view
GHCi, version 7.4.1: http://www.haskell.org/ghc/&amp;#160; :? for help
Loading package ghc-prim ... linking ... done.
&lt;em&gt;[..]&lt;/em&gt;
Loading package ghc-7.4.1 ... linking ... done.
Loading package ghc-heap-view-0.1 ... linking ... done.
Prelude&amp;gt; let {a = [1,2,3,4]; b = 5:a}
Prelude&amp;gt; :m + GHC.HeapView 
Prelude GHC.HeapView&amp;gt; rawHeapData &amp;lt;- getClosureRaw b
Prelude GHC.HeapView&amp;gt; rawHeapData 
(0x000000004080d658,[1082185320,140040739366568,140040739365928],[0x00007f5dc68626a8,0x00007f5dc6862428])
Prelude GHC.HeapView&amp;gt; System.Mem.performGC
Prelude GHC.HeapView&amp;gt; rawHeapData 
(0x000000004080d658,[1082185320,140040739366568,140040739365928],[0x00007f5dc41b3ad8,0x00007f5dc41b3b28]) 
&lt;/pre&gt; 
&lt;p&gt;The function &lt;tt&gt;rawHeapData&lt;/tt&gt; is a thin wrapper around &lt;tt&gt;slurpClosure#&lt;/tt&gt; which turns the primitive array in normal lists. Note that the second component of the triple is unchanged, but the third is updated by the garbage collector. Of course this means that the &lt;tt&gt;Show&lt;/tt&gt; instance for the data type that ghc-heap-view uses to reference values is not referential transparent either.&lt;/p&gt; 
&lt;p&gt;The foreign function import above is of type “&lt;a href=&quot;http://hackage.haskell.org/trac/ghc/wiki/Commentary/PrimOps#Foreignout-of-linePrimOps&quot;&gt;&lt;tt&gt;prim&lt;/tt&gt;&lt;/a&gt;”, i.e. does not call a C function but rather a Cmm function. &lt;a href=&quot;http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/CmmType&quot;&gt;Cmm&lt;/a&gt; is a reduced C that GHC uses internally to compile the Haskell code to, and most primitive operations are implemented in this language – although I do quickly call regular C from &lt;a href=&quot;http://darcs.nomeata.de/ghc-heap-view/cbits/HeapViewPrim.cmm&quot;&gt;my Cmm&lt;/a&gt;&lt;a href=&quot;http://darcs.nomeata.de/ghc-heap-view/cbits/HeapViewPrim.cmm&quot;&gt; code&lt;/a&gt; to do &lt;a href=&quot;http://darcs.nomeata.de/ghc-heap-view/cbits/HeapView.c&quot;&gt;the more complicated stuff&lt;/a&gt;, mainly figuring out what words of the closure are pointers.&lt;/p&gt; 
&lt;p&gt;The knowledgeable reader might notice that I am passing a boxed value of type &lt;a href=&quot;http://hackage.haskell.org/packages/archive/ghc-prim/0.2.0.0/doc/html/GHC-Prim.html#t%3AAny&quot;&gt;&lt;tt&gt;Any&lt;/tt&gt;&lt;/a&gt; to the foreign function. This is currently not possible with foreign prim functions, and to actually use that code, you need the patch in &lt;a href=&quot;http://hackage.haskell.org/trac/ghc/ticket/5931&quot;&gt;GHC ticket #5931&lt;/a&gt;. But you can use ghc-heap-view without that as well (and the Cabal package will by default use that path), using the following hack to obtain the pointer to a Haskell value on the Heap as an unboxed type that can pass to the primitive operation:&lt;/p&gt; 
&lt;pre&gt;foreign import prim &quot;slurpClosurezh&quot; slurpClosure&#039;# :: Word#  -&amp;gt; (# Addr#, ByteArray#, Array# b #)
data Ptr&#039; a = Ptr&#039; a
aToWord# :: Any -&amp;gt; Word#
aToWord# a = case Ptr&#039; a of mb@(Ptr&#039; _) -&amp;gt; case unsafeCoerce# mb :: Word of W# addr -&amp;gt; addr
slurpClosure# :: Any -&amp;gt; (# Addr#, ByteArray#, Array# b #)
slurpClosure# a = slurpClosure&#039;# (aToWord# a)
&lt;/pre&gt; 
&lt;p&gt;This works because a &lt;a href=&quot;http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-Exts.html#t:Word&quot;&gt;&lt;tt&gt;Word&lt;/tt&gt;&lt;/a&gt; and a &lt;tt&gt;Ptr&#039;&lt;/tt&gt; have the same closure layout, only differing in the fact that one stores an &lt;tt&gt;a&lt;/tt&gt;, and the other stores a &lt;tt&gt;Word#&lt;/tt&gt;.&lt;/p&gt; 
&lt;p&gt;Once we obtained the raw representation of the closure, we do the parsing in Haskell. Using the info table and the raw closure, we have enough information to tell which words have to be replaced by the appropriate pointer (which might already have been updated by the garbage collector) in the pointers list.&lt;/p&gt; 
&lt;p&gt;This work was supported by a scholarship from the &lt;a href=&quot;http://telekom-stiftung.de/&quot;&gt;Deutsche Telekom Stiftung&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 13 Mar 2012 10:52:00 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/548-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F548-ghc-heap-view-Complete-referential-opacity.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>GHC 7.4.1 speeds up arbtt by a factor of 22</title>
    <link>http://www.joachim-breitner.de/blog/archives/546-GHC-7.4.1-speeds-up-arbtt-by-a-factor-of-22.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/546-GHC-7.4.1-speeds-up-arbtt-by-a-factor-of-22.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=546</wfw:comment>

    <slash:comments>5</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=546</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;More than two years ago I wrote &lt;a href=&quot;http://www.joachim-breitner.de/projects#arbtt&quot;&gt;arbtt&lt;/a&gt;, a tool that silently records what programs you are using and allows you to do statistics on that data later, based on rules that you define &lt;em&gt;afterwards&lt;/em&gt;, hence the name &lt;strong&gt;a&lt;/strong&gt;utomatic &lt;strong&gt;r&lt;/strong&gt;ule &lt;strong&gt;b&lt;/strong&gt;ased &lt;strong&gt;t&lt;/strong&gt;ime &lt;strong&gt;t&lt;/strong&gt;racker. I wasn’t doing much with it recently (the last release has been half a year ago), but it nevertheless was running on my machine and by now has tracked a total time span of 248 days in 350000 records.&lt;/p&gt; 
&lt;p&gt;Yesterday, I had a use for it again: measuring the time spent creating a certain document with LaTeX. So I added a rule to my &lt;a href=&quot;http://darcs.nomeata.de/arbtt/categorize.cfg&quot;&gt;categorize.cfg&lt;/a&gt; and ran &lt;a href=&quot;http://darcs.nomeata.de/arbtt/doc/users_guide/arbtt-stats.html&quot;&gt;arbtt-stats&lt;/a&gt;. I knew that it was not very fast, and that my data set has grown considerably since I last used it. And indeed, it took more than 6 minutes to process the data and spit out the result.&lt;/p&gt; 
&lt;p&gt;Since I’m currently working on the GHC 7.4.1 transition in Debian anyways, I decided to check what happens if I compile the code with that version of the Haskell compiler, instead of the previous version 7.0.4. And behold: The whole process took merely 17.3 seconds to complete! At first I did not believe it, but the result was identical, both binaries were built with the same option, i.e. no profiling enabled or anything like that. Wouldn’t you also like to have such speed ups for free, just by waiting for someone else to improve their work?&lt;/p&gt; 
&lt;p class=&quot;caption&quot;&gt;I tried to find out the reason for the speed up and created profiling output from both the &lt;a href=&quot;http://darcs.nomeata.de/arbtt/doc/profdata/arbtt-stats-7.0.4.prof&quot;&gt;old&lt;/a&gt; and the &lt;a href=&quot;http://darcs.nomeata.de/arbtt/doc/profdata/arbtt-stats-7.4.1.prof&quot;&gt;new&lt;/a&gt; binary. The old binary spends 83% of the time in Categorize.checkRegex, which basically just call &lt;a href=&quot;http://hackage.haskell.org/packages/archive/pcre-light/0.4/doc/html/Text-Regex-PCRE-Light.html#v:match&quot;&gt;Text.Regex.PCRE.Light.match&lt;/a&gt;. Since the version of &lt;a href=&quot;http://hackage.haskell.org/package/pcre-light&quot;&gt;pcre-light&lt;/a&gt; is the same in both binaries, I conclude that the Foreign Function Interface that GHC provides to interact with C libraries (&lt;a href=&quot;http://www.pcre.org/&quot;&gt;libpcre&lt;/a&gt; in this case) is much faster now, although I do not find any mention in the &lt;a href=&quot;http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/release-7-4-1.html&quot;&gt;release notes&lt;/a&gt;. And even if I do not count the 83% time spent in checkRegex, the code from the new compiler is still 2.7 times faster. Thanks, GHC devs, great work!&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Sun, 26 Feb 2012 17:25:00 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/546-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F546-GHC-7.4.1-speeds-up-arbtt-by-a-factor-of-22.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>Guest lecture on Haskell performance</title>
    <link>http://www.joachim-breitner.de/blog/archives/539-Guest-lecture-on-Haskell-performance.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/539-Guest-lecture-on-Haskell-performance.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=539</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=539</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;Today, I had some business in Bonn, so &lt;a href=&quot;http://www.iai.uni-bonn.de/~jv/&quot;&gt;Janis Voigtländer&lt;/a&gt; invited me to hold a guest lecture in his &lt;a href=&quot;http://www.iai.uni-bonn.de/~jv/teaching/ffp/&quot;&gt;advanced functional programming course&lt;/a&gt;, maybe telling the students more about “real world” use of Haskell, given that he teaches mostly the theoretical foundations. I chose to discuss an experience I made while implementing &lt;a href=&quot;http://lists.debian.org/debian-release/2011/07/msg00370.html&quot;&gt;SAT-Britney&lt;/a&gt;, namely that for the sake of good runtime and memory performance, it may be neither ideal to evaluate a list fully lazily, nor fully strict, but to have something in between. For the talk, I demonstrated this by a small example, showed how to use the GHCi debugger to get some insight in the evaluation order of things, how to benchmark the program and read the ghc statistics and a profiling chart, and finally how to get the most out of GHC’s &lt;a href=&quot;http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/rewrite-rules.html#id641682&quot;&gt;List Fusion&lt;/a&gt;. I wanted to also touch on QuickCheck, but skipped it to finish in time. The &lt;a href=&quot;http://www.joachim-breitner.de/publications/haskell_performance_bonn_2011-12-06.pdf&quot;&gt;full text of my talk&lt;/a&gt; (including graphs) is available, but in German; if you want an English version convince your prof to invite me for a guest lecture as well.&lt;/p&gt; 
&lt;p&gt;Afterwards I sat down with one of the students of the course, Helmut Grohne, who happened to take part in the &lt;a href=&quot;http://blog.schmehl.info/Debian/events/bsp-hi-2011-3&quot;&gt;Debian bug squashing party&lt;/a&gt; last weekend and had filed a &lt;a href=&quot;http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=650808&quot;&gt;release critical&lt;/a&gt; bug against the Haskell grammar generator &lt;a href=&quot;http://www.cs.ox.ac.uk/people/ralf.hinze/talks/Frown.pdf&quot;&gt;frown&lt;/a&gt; (no better link available, homepage seems to be down) to debug the problem. It quickly became clear that the bug &lt;a href=&quot;http://patch-tracker.debian.org/patch/series/view/frown/0.6.1-11/07_no-n-plus-k-pattern&quot;&gt;was introduced by me&lt;/a&gt; (can you spot it?) when trying to make it compile with a modern GHC – slightly embarrassing for me.&lt;br /&gt; &lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 06 Dec 2011 22:16:28 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/539-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F539-Guest-lecture-on-Haskell-performance.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>First contribution to a basic Haskell library</title>
    <link>http://www.joachim-breitner.de/blog/archives/534-First-contribution-to-a-basic-Haskell-library.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/534-First-contribution-to-a-basic-Haskell-library.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=534</wfw:comment>

    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=534</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;While working on &lt;a href=&quot;http://lists.debian.org/debian-release/2011/07/msg00370.html&quot;&gt;SAT-Britney&lt;/a&gt;, I made heavy use of the &lt;a href=&quot;http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-IntSet.html#t:IntSet&quot;&gt;IntSet&lt;/a&gt; data type provided by the basic Haskell library “&lt;a href=&quot;http://hackage.haskell.org/package/containers&quot;&gt;containers&lt;/a&gt;”. Since memory consumption was a problem, I looked at its implementation, which is a binary tree, and &lt;a href=&quot;http://www.haskell.org/pipermail/libraries/2011-September/016752.html&quot;&gt;wondered&lt;/a&gt; whether this could be improved for dense sets by using a machine sized word as a bit map to represent a continuous part of the integers, so I started to implement it. The effect on my program was not as strong as I had hoped for, but nevertheless, the code &lt;a href=&quot;https://github.com/haskell/containers/pull/3&quot;&gt;made its way&lt;/a&gt; back into containers – after a thorough review and a &lt;a href=&quot;https://github.com/haskell/containers/commit/4ba5d5717ab05ed73ead4009a5e1a1c24e6899b5&quot;&gt;considerable&lt;/a&gt; &lt;a href=&quot;https://github.com/haskell/containers/commit/92d55cc509c9b44ce7d536a00ba4994aa1aeea9c&quot;&gt;amount&lt;/a&gt; &lt;a href=&quot;https://github.com/haskell/containers/commit/a7d29bd7f934c30f5c089fe6a34b63cfdc292880&quot;&gt;of&lt;/a&gt; &lt;a href=&quot;https://github.com/haskell/containers/commit/e076b33f4cee3f657b5bdc5bf6f5a4c9e249d00c&quot;&gt;further&lt;/a&gt; &lt;a href=&quot;https://github.com/haskell/containers/commit/4ee739a52a68a7b4397b5d2ed1cd3e8d4f98fe1a&quot;&gt;improvements&lt;/a&gt; by &lt;a href=&quot;https://github.com/foxik&quot;&gt;Milan Straka&lt;/a&gt;. I’m getting sucked deeper and deeper into the Haskell community... (which means that the Haskell community does not suck, of course.)&lt;/p&gt; 
    </content:encoded>

    <pubDate>Tue, 22 Nov 2011 21:15:36 +0100</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/534-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F534-First-contribution-to-a-basic-Haskell-library.html&amp;user_id=nomeata" type="text/html" />
</item>
<item>
    <title>stm-stats published for factis research</title>
    <link>http://www.joachim-breitner.de/blog/archives/524-stm-stats-published-for-factis-research.html</link>
            <category>English</category>
            <category>Haskell</category>
    
    <comments>http://www.joachim-breitner.de/blog/archives/524-stm-stats-published-for-factis-research.html#comments</comments>
    <wfw:comment>http://www.joachim-breitner.de/blog/wfwcomment.php?cid=524</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.joachim-breitner.de/blog/rss.php?version=2.0&amp;type=comments&amp;cid=524</wfw:commentRss>
    

    <author>mail@joachim-breitner.de (nomeata)</author>
    <content:encoded>
    &lt;p&gt;&lt;a href=&quot;http://www.factisresearch.com/&quot;&gt;Factis research&lt;/a&gt; has hired me to make sure their code gets contributed back to the Haskell community. As a first step, I have followed a request of someone in the audience of &lt;a href=&quot;http://factisresearch.blogspot.com/2011/10/yesterday-i-gave-talk-at-haskell-in.html&quot;&gt;Stefan Wehr’s talk&lt;/a&gt; at &lt;a href=&quot;https://portal.imn.htwk-leipzig.de/events/hal6-haskell-workshop&quot;&gt;HaL 6&lt;/a&gt; and prepared &lt;a href=&quot;http://hackage.haskell.org/package/stm-stats&quot;&gt;stm-stats&lt;/a&gt; – seem &lt;a href=&quot;http://factisresearch.blogspot.com/2011/10/stm-stats-retry-statistics-for-stm.html&quot;&gt;my post at the factis research blog&lt;/a&gt; about that.&lt;/p&gt; 
    </content:encoded>

    <pubDate>Sun, 09 Oct 2011 22:28:56 +0200</pubDate>
    <guid isPermaLink="false">http://www.joachim-breitner.de/blog/archives/524-guid.html</guid>
    
    <atom:link rel="payment" href="https://flattr.com/submit/auto?url=http%3A%2F%2Fwww.joachim-breitner.de%2Fblog%2Farchives%2F524-stm-stats-published-for-factis-research.html&amp;user_id=nomeata" type="text/html" />
</item>

</channel>
</rss>
