<?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>LAMBDAPHONE &#187; hackage</title>
	<atom:link href="http://coder.bsimmons.name/blog/tag/hackage/feed/" rel="self" type="application/rss+xml" />
	<link>http://coder.bsimmons.name/blog</link>
	<description>fragmentary ideas  ䷿  intellectual what-nots  ䷷  and haskell programming  ䷴</description>
	<lastBuildDate>Sun, 29 Jan 2012 17:24:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>New version of &#8216;thrist&#8217; package released</title>
		<link>http://coder.bsimmons.name/blog/2010/11/new-version-of-thrist-package-released/</link>
		<comments>http://coder.bsimmons.name/blog/2010/11/new-version-of-thrist-package-released/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 16:48:47 +0000</pubDate>
		<dc:creator>jberryman</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[hackage]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[theory]]></category>

		<guid isPermaLink="false">http://coder.bsimmons.name/blog/?p=478</guid>
		<description><![CDATA[<p>I&#8217;ve been collaborating with Gabor Greif on a <a href="http://hackage.haskell.org/package/thrist">new version of his &#8216;thrist&#8217; module</a>, which was just released last night! I approached Gabor with some new ideas that came to me as I was writing a module that uses&#8230; <a href="http://coder.bsimmons.name/blog/2010/11/new-version-of-thrist-package-released/" class="read_more">   [ R E A D &#124; M O R E ]</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been collaborating with Gabor Greif on a <a href="http://hackage.haskell.org/package/thrist">new version of his &#8216;thrist&#8217; module</a>, which was just released last night! I approached Gabor with some new ideas that came to me as I was writing a module that uses Thrists heavily, and he invited me to co-author this version. (See <a href="#thrist_primer">below</a> for a brief explanation of Thrists).</p>
<p>I noticed that in the previous version, the function <code>foldThrist</code> was essentially a <code>foldr</code> with a type signature that was overly restrictive. </p>
<p>For instance, one <em>could not</em> define an identity function on Thrists in terms of the foldThrist function, the way one can with regular lists, e.g.:</p>
<blockquote><p><code>
<pre>foldr (:) [] [1..4] == [1,2,3,4]</pre>
<p></code></p></blockquote>
<p>Other additions followed as I tried to define the Thrist equivalent of many useful list functions. For example I wanted to define a <code>foldl</code>-like function that we could use to reverse a Thrist.</p>
<p>Check out <a href="http://heisenbug.blogspot.com/2010/11/cooperation.html">the release announcement</a> on Gabor&#8217;s blog, along with his <a href="http://www.opendylan.org/~gabor/Thrist-draft-2008-07-18.pdf">draft paper on Thrists.</a><br />
<span id="more-478"></span></p>
<h3>A Brief Thrist Primer<a name="thrist_primer"></a></h3>
<p>A Thrist is a <strong>type-threaded list</strong>. This is easiest explained with an example:</p>
<blockquote><p><code><br />
*Data.Thrist> :t Cons (True,'z')$ Cons ('a',"bar")$ Cons ("foo",3.14) Nil<br />
<strong>Cons (True,'z')$ Cons ('a',"bar")$ Cons ("foo",3.14) Nil<br />
  :: (Fractional c) => Thrist (,) Bool c</strong><br />
</code></p></blockquote>
<p>As you can see, unlike the regular haskell list type which takes a single type for each element, the Thrist takes a single <em>binary type</em> (in the case above we have the tuple type:<code> (,)</code>) for each element, whose type arguments are <em>chained</em> together. So the <em>second</em> type argument of one cell must be the same type as the <em>first</em> type argument of the following cell, and so on.</p>
<p>The two arguments that are visible in the outer Thrist type itself are the first argument of the first cell, and the second argument of the last cell. In the example above those would be <code>Bool</code> (taken from the <code>True</code> value fst of the head of our Thrist), and some as-yet-undetermined <code>Fractional</code> type (our 3.14 value).</p>
<p>This type of cool data structure is only possible because of <a href="http://en.wikibooks.org/wiki/Haskell/GADT">GADTs</a> which let us enforce the type-threading and allow us to have all these types <em>inside the Thrist</em> without having them show up in the type signature.</p>
<p>Here is how the Thrist GADT is defined:</p>
<p><blockquote class="vimblock"><br />
<span class="Type">data</span>&nbsp;Thrist&nbsp;<span class="Statement">::</span>&nbsp;(<span class="Statement">*</span>&nbsp;<span class="Statement">-&gt;</span>&nbsp;<span class="Statement">*</span>&nbsp;<span class="Statement">-&gt;</span>&nbsp;<span class="Statement">*</span>)&nbsp;<span class="Statement">-&gt;</span>&nbsp;<span class="Statement">*</span>&nbsp;<span class="Statement">-&gt;</span>&nbsp;<span class="Statement">*</span>&nbsp;<span class="Statement">-&gt;</span>&nbsp;<span class="Statement">*</span>&nbsp;<span class="Type">where</span><br />
&nbsp;&nbsp;Nil&nbsp;<span class="Statement">::</span>&nbsp;Thrist&nbsp;(<span class="Statement">~&gt;</span>)&nbsp;a&nbsp;a<br />
&nbsp;&nbsp;Cons&nbsp;<span class="Statement">::</span>&nbsp;(a&nbsp;<span class="Statement">~&gt;</span>&nbsp;b)&nbsp;<span class="Statement">-&gt;</span>&nbsp;Thrist&nbsp;(<span class="Statement">~&gt;</span>)&nbsp;b&nbsp;c&nbsp;<span class="Statement">-&gt;</span>&nbsp;Thrist&nbsp;(<span class="Statement">~&gt;</span>)&nbsp;a&nbsp;c<br />
<br /></blockquote></p>
<p>Here is another example of a Thrist in which the binary type element is a <em>function</em>:</p>
<blockquote><pre>
*Data.Thrist> :t Cons head $ Cons fst $ Cons not Nil
<strong>Cons head $ Cons fst $ Cons not Nil
    :: Thrist (->) [(Bool, b)] Bool</strong></pre>
</blockquote>
<p>It might look odd to see (->) used by itself as an argument to a type signature, but a Thrist of functions is actually pretty cool. We can actual fold the Thrist using function composition:</p>
<blockquote>
<p><code>*Data.Thrist> :t foldl1Thrist (flip (.)) $ Cons head $ Cons fst $ Cons not Nil<br />
<strong>foldl1Thrist (flip (.))$ Cons head $ Cons fst $ Cons not Nil<br />
  :: [(Bool, b)] -> Bool</strong></code></p></blockquote>
<p>Notice how similar the Thrist definition is to the composed function. You can see how the Thrist generalizes function composition to a certain extent.</p>
]]></content:encoded>
			<wfw:commentRss>http://coder.bsimmons.name/blog/2010/11/new-version-of-thrist-package-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Befunge-93 Interpreter on Hackage</title>
		<link>http://coder.bsimmons.name/blog/2010/05/befunge-93-interpreter-on-hackage/</link>
		<comments>http://coder.bsimmons.name/blog/2010/05/befunge-93-interpreter-on-hackage/#comments</comments>
		<pubDate>Thu, 20 May 2010 18:36:42 +0000</pubDate>
		<dc:creator>jberryman</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[EsotericLanguages]]></category>
		<category><![CDATA[hackage]]></category>
		<category><![CDATA[MonadTransformers]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://coder.bsimmons.name/blog/?p=413</guid>
		<description><![CDATA[<p>I&#8217;ve fixed a bug related to upgrading GHC to version 6.12 (thanks to Cale and the folks on haskell-cafe who helped me with the issue) and got my <a href="http://en.wikipedia.org/wiki/Befunge">Befunge-93</a> interpreter up on hackage. The program is written in haskell&#8230; <a href="http://coder.bsimmons.name/blog/2010/05/befunge-93-interpreter-on-hackage/" class="read_more">   [ R E A D &#124; M O R E ]</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve fixed a bug related to upgrading GHC to version 6.12 (thanks to Cale and the folks on haskell-cafe who helped me with the issue) and got my <a href="http://en.wikipedia.org/wiki/Befunge">Befunge-93</a> interpreter up on hackage. The program is written in haskell (as usual). You should be able to get it soon with a:</p>
<blockquote><pre>$> cabal install Befunge93</pre>
</blockquote>
<p>If you want to read about how I designed it you can check out the source above, or take a look at my <a href="http://coder.bsimmons.name/blog/2010/01/a-befunge-93-interpreter/">previous blog post</a>.</p>
<p>Please report any bugs to me, and I&#8217;m also very interested in patches or suggestions for performance improvements if anyone ends up being interested in this program.</p>
<p><strong>EDIT</strong>: Here is the package page: <a href="http://hackage.haskell.org/package/Befunge93">http://hackage.haskell.org/package/Befunge93</a></p>
]]></content:encoded>
			<wfw:commentRss>http://coder.bsimmons.name/blog/2010/05/befunge-93-interpreter-on-hackage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lazy Arithmetic in Haskell</title>
		<link>http://coder.bsimmons.name/blog/2010/03/lazy-arithmetic-in-haskell/</link>
		<comments>http://coder.bsimmons.name/blog/2010/03/lazy-arithmetic-in-haskell/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 17:24:08 +0000</pubDate>
		<dc:creator>jberryman</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[hackage]]></category>
		<category><![CDATA[laziness]]></category>
		<category><![CDATA[NumericTypes]]></category>

		<guid isPermaLink="false">http://coder.bsimmons.name/blog/?p=372</guid>
		<description><![CDATA[<p><em>We don&#8217;t usually give much thought to Numeric data types beyond whether we want to work with integers or decimal numbers. And that is a shame! In this post I&#8217;ll look at how we can actually do arithmetic operations lazily,</em>&#8230; <a href="http://coder.bsimmons.name/blog/2010/03/lazy-arithmetic-in-haskell/" class="read_more">   [ R E A D &#124; M O R E ]</a></p>]]></description>
			<content:encoded><![CDATA[<p><em>We don&#8217;t usually give much thought to Numeric data types beyond whether we want to work with integers or decimal numbers. And that is a shame! In this post I&#8217;ll look at how we can actually do arithmetic operations lazily, and in the process hopefully reveal a bit about haskell&#8217;s numeric classes.</em></p>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;<span class="Type">module</span>&nbsp;LazyArithmetic<br />
<span class="Comment">&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp; <span class="Type">where</span><br />
<br /></div></p>
<p>We will be using <a href="http://hackage.haskell.org/package/numbers-2009.8.9">Lennart Augustsson&#8217;s <code>numbers</code> library</a> which can be installed from hackage with <a href="http://hackage.haskell.org/trac/hackage/wiki/CabalInstall">cabal-install</a>:</p>
<blockquote><p>$> cabal install numbers</p></blockquote>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;<span class="PreProc">import</span>&nbsp;Data.Number.Natural<br />
<span class="Comment">&gt;</span>&nbsp;<span class="PreProc">import</span>&nbsp;Data.List(genericLength)<br />
<br /></div></p>
<p>Consider two functions: the Prelude function <code>sum</code> and <code>genericLength</code> from the List library:</p>
<p><blockquote class="vimblock"><br />
<span class="Comment"></span>&nbsp;<span class="Identifier">genericLength</span>&nbsp;<span class="Statement">::</span>&nbsp;(<span class="Type">Num</span>&nbsp;i)&nbsp;<span class="Statement">=&gt;</span>&nbsp;[b]&nbsp;<span class="Statement">-&gt;</span>&nbsp;i<br />
<span class="Comment"></span>&nbsp;<span class="Identifier">sum</span>&nbsp;<span class="Statement">::</span>&nbsp;(<span class="Type">Num</span>&nbsp;a)&nbsp;<span class="Statement">=&gt;</span>&nbsp;[a]&nbsp;<span class="Statement">-&gt;</span>&nbsp;a<br />
<br /></blockquote></p>
<p>&#8230;two simple functions that have the potential to be very expensive, depending on the length of the list and the values of the elements.<br />
<span id="more-372"></span><br />
Say for instance that all we want is to use:</p>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;sumLengths&nbsp;<span class="Statement">=</span>&nbsp;<span class="Identifier">sum</span>&nbsp;<span class="Statement">.</span>&nbsp;<span class="Identifier">map</span>&nbsp;genericLength<br />
<span class="Comment">&gt;</span><br />
<span class="Comment">&gt;</span>&nbsp;checkLengths&nbsp;as&nbsp;n&nbsp;<span class="Statement">=</span>&nbsp;(sumLengths&nbsp;as&nbsp;<span class="Statement">`div`</span>&nbsp;n)&nbsp;<span class="Statement">&gt;</span>&nbsp;<span class="Constant">2</span><br />
<br /></div></p>
<p>The <code>checkLengths</code> function above has to count every element of every element of every sub-list in order to return a <code>Bool</code> value, and if any of those lists are infinite our program will never terminate:</p>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;hopeless&nbsp;<span class="Statement">=</span>&nbsp;checkLengths&nbsp;[[<span class="Constant">'a'</span><span class="Statement">..</span><span class="Constant">'z'</span>],&nbsp;[<span class="Constant">'0'</span>],&nbsp;<span class="Identifier">repeat</span>&nbsp;<span class="Constant">'Z'</span>]&nbsp;&nbsp;<span class="Constant">99</span><br />
<br /></div></p>
<p><em>&#8230;or so we might think!</em></p>
<h3>Lazy Natural Numbers</h3>
<p>It turns out we can solve our seemingly hopeless situation with a type signature:</p>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;sumLengths&nbsp;<span class="Statement">::</span>&nbsp;[[b]]&nbsp;<span class="Statement">-&gt;</span>&nbsp;Natural<br />
<br /></div></p>
<p>And suddenly, as if by magic:</p>
<blockquote><p><code>*LazyArithmetic> hopeless<br />
True</code></p></blockquote>
<p>What&#8217;s going on here? Well it turns out the problem is that Haskell&#8217;s built-in numeric types are boring, old-fashioned and (in some cases) just plain wrong. But let&#8217;s step behind the curtain and look at how the Data.Numbers library defines the Natural type internally:</p>
<p><blockquote class="vimblock"><br />
<span class="Comment"></span>&nbsp;<span class="Type">data</span>&nbsp;Natural&nbsp;<span class="Statement">=</span>&nbsp;Z&nbsp;<span class="Statement">|</span>&nbsp;S&nbsp;Natural<br />
<br /></blockquote></p>
<p>We see that we&#8217;re using an abstract data type to represent non-negative integers, and it looks nearly identical to our list type <code>[]</code>. The upshot of that is we gain, in our numeric type and arithmetic operations, the same type of laziness that lists afford us!</p>
<p>So in the above example, <code>hopeless</code>, we need only carry out the operations far enough to see that the result is <code>> 2</code>.</p>
<p>The numeric type in <code>Data.List.Natural</code> are actually known as <a href="http://www.haskell.org/haskellwiki/Peano_numbers">Peano numbers</a>. They are essentially just lists of units and, as you might imagine, are not the most efficient way to represent an integer.</p>
<p>But they are exactly what we want for this application. If we failed to realize that we could solve our problem with an appropriate numeric representation, we might try to rig up something like this:</p>
<p><div class="vimblock"><br />
<span class="Comment">&gt;</span>&nbsp;checkLengthsUnclear&nbsp;as&nbsp;n&nbsp;<span class="Statement">=</span>&nbsp;<span class="Identifier">not</span>&nbsp;<span class="Statement">$</span>&nbsp;<span class="Identifier">null</span>&nbsp;<span class="Statement">$</span>&nbsp;<span class="Identifier">drop</span>&nbsp;(n<span class="Statement">*</span><span class="Constant">2</span>)&nbsp;<span class="Statement">$</span>&nbsp;<span class="Identifier">concat</span>&nbsp;as<br />
<br /></div></p>
<p>&#8230;which works identically to <code>checkLengths</code> with Peano Numbers, but completely obfuscates the intention of the function. As usual laziness gives us <em>expressive power</em> rather than an efficiency boost.</p>
<h3>Limitations, Haskell&#8217;s Numeric Type Classes, and the Numeric Prelude</h3>
<p>The <code>Data.Number.Natural</code> library is convenient because it provides Num and Integral instances so we can use the the Natural type with any function that is polymorphic on those classes.</p>
<p>The problem is <a href="http://hackage.haskell.org/packages/archive/numbers/2009.8.9/doc/html/src/Data-Number-Natural.html#line-44">the Num instance</a> is incomplete and error-prone: and that&#8217;s because a <a href="http://en.wikipedia.org/wiki/Natural_number">natural numbe</a>r type <em>shouldn&#8217;t be an instance of Num</em>! We can&#8217;t negate a Natural, which in turn makes subtraction dangerous, etc.</p>
<blockquote><p><code>*LazyArithmetic> let x = 1 :: Natural; y = 2 in x - y<br />
*** Exception: Natural: (-)</code></p></blockquote>
<p>We might wish that haskell&#8217;s Numeric type classes were more expressive, allowing for more abstract numeric types. For example it might be more &#8220;haskelly&#8221; for the length function to be defined with the type:</p>
<p><blockquote class="vimblock"><br />
<span class="Comment"></span>&nbsp;<span class="Identifier">length</span>&nbsp;<span class="Statement">::</span>&nbsp;Natural&nbsp;n&nbsp;<span class="Statement">=&gt;</span>&nbsp;[a]&nbsp;<span class="Statement">-&gt;</span>&nbsp;n<br />
<br /></blockquote></p>
<p>After all we don&#8217;t use integers for boolean values as in C; we have the abstract type <code>Bool</code>. So why return an Int when a Natural type (or class) might be more expressive? The answer of course is that that gets really complicated really fast. </p>
<p>For one approach at making haskell&#8217;s numeric class hierarchy more expressive and flexible, check out the <a href="http://www.haskell.org/haskellwiki/Numeric_Prelude">Numeric Prelude</a>. It&#8217;s <a href="http://hackage.haskell.org/package/numeric-prelude">haddock documentation</a> is very thorough and an interesting read, and you can see the sheer number of design decisions necessary for such an undertaking. </p>
<p>For some other approaches and links, see <a href="http://www.haskell.org/haskellwiki/Libraries_and_tools/Mathematics#Type_class_hierarchies">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://coder.bsimmons.name/blog/2010/03/lazy-arithmetic-in-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>directory-tree module released</title>
		<link>http://coder.bsimmons.name/blog/2009/05/directory-tree-module-released/</link>
		<comments>http://coder.bsimmons.name/blog/2009/05/directory-tree-module-released/#comments</comments>
		<pubDate>Sat, 09 May 2009 16:33:12 +0000</pubDate>
		<dc:creator>jberryman</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[hackage]]></category>
		<category><![CDATA[IO]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[Tree]]></category>

		<guid isPermaLink="false">http://coder.bsimmons.name/blog/?p=148</guid>
		<description><![CDATA[<p>I&#8217;ve released my first package, <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/directory-tree">up now on hackage</a> (haddock docs should be generated soon). The module provides a simple data structure that mirrors a directory tree, and some useful functions for doing IO on directories of files. You&#8230; <a href="http://coder.bsimmons.name/blog/2009/05/directory-tree-module-released/" class="read_more">   [ R E A D &#124; M O R E ]</a></p>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released my first package, <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/directory-tree">up now on hackage</a> (haddock docs should be generated soon). The module provides a simple data structure that mirrors a directory tree, and some useful functions for doing IO on directories of files. You can <a href="http://coder.bsimmons.name/blog/2009/04/a-directorytree-module-and-some-examples/">read more about it here</a>.</p>
<p>It&#8217;s very likely there are some bugs, especially related to cross platform issues with file names and paths. The module is also fairly bare, so please send me any requests for functionality that I haven&#8217;t thought of, as well as any bugs you might find. </p>
<p>You can install it with:</p>
<blockquote><p>$ cabal install directory-tree</p></blockquote>
<p>And get the source with:</p>
<blockquote><p>$ darcs get http://coder.bsimmons.name/code/DirectoryTree/</p></blockquote>
<p>I hope this is useful to someone!</p>
<p><strong>UPDATE</strong>: I&#8217;ve just released v0.9.0 of this package which has a number of sneaky changes and additions, most notably the inclusion of a <code>readDirectoryWithL</code> function that allows for lazy directory reading IO. This will let users work with a DirTree read from disk just as if it was a pure lazy data structure, while IO is done in the background as needed. No more exploding code! (hopefully)</p>
]]></content:encoded>
			<wfw:commentRss>http://coder.bsimmons.name/blog/2009/05/directory-tree-module-released/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk
Database Caching 8/15 queries in 0.032 seconds using disk

Served from: coder.bsimmons.name @ 2012-02-05 11:19:42 -->
