<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Codes on Brandon Simmons&#39; website</title>
    <link>https://brandon.si/code/</link>
    <description>Recent content in Codes on Brandon Simmons&#39; website</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 02 Jan 2026 22:34:34 -0500</lastBuildDate>
    <atom:link href="https://brandon.si/code/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Sandbox Minus John Dillinger Equals What?</title>
      <link>https://brandon.si/code/sandbox-minus-john-dillinger/</link>
      <pubDate>Fri, 12 Dec 2025 18:43:03 -0500</pubDate>
      <guid>https://brandon.si/code/sandbox-minus-john-dillinger/</guid>
      <description>&lt;p&gt;&lt;em&gt;It didn&amp;rsquo;t look like anyone had ever tried to answer the&#xA;&lt;a href=&#34;https://en.wikipedia.org/wiki/Trout_Fishing_in_America&#34;&gt;question&lt;/a&gt;,&#xA;so I thought I would have a go. This post probably won&amp;rsquo;t be interesting to&#xA;folks already familiar with embeddings or linear algebra. It represents my&#xA;rough, non-expert understanding of the subject matter&lt;/em&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Huh. What could it mean to subtract two words, and how&#xA;would you even do that? If we just consider the &lt;em&gt;how&lt;/em&gt;, it&amp;rsquo;s not too hard to&#xA;come up with a scheme. You could map a word to its place in the dictionary,&#xA;say, then subtract the numbers and interpret the result &lt;code&gt;N&lt;/code&gt; to mean the &lt;code&gt;Nth&lt;/code&gt;&#xA;word. But that&amp;rsquo;s not interesting, because alphabetical order (the basis of our&#xA;mapping) is totally unrelated to a word&amp;rsquo;s &lt;em&gt;meaning&lt;/em&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Linking Smaller Haskell Binaries</title>
      <link>https://brandon.si/code/linking-smaller-haskell-binaries/</link>
      <pubDate>Sat, 07 Jan 2023 15:52:00 -0500</pubDate>
      <guid>https://brandon.si/code/linking-smaller-haskell-binaries/</guid>
      <description>&lt;p&gt;Haskell binaries can get quite large (think ~100MB), especially for projects&#xA;with many transitive dependencies. Here are two strategies that can help at&#xA;link time, the latter being more experimental.&lt;/p&gt;&#xA;&lt;p&gt;I used the &lt;code&gt;test-pandoc&lt;/code&gt; binary from &lt;a href=&#34;https://github.com/jgm/pandoc&#34;&gt;pandoc&lt;/a&gt; on&#xA;GHC 9.2.5 below. This was nice because obviously it was easy to test if linking&#xA;broke anything (just run the tests).&lt;/p&gt;&#xA;&lt;h2 id=&#34;-split-sections-and---gc-sections&#34;&gt;&lt;code&gt;-split-sections&lt;/code&gt; and &lt;code&gt;--gc-sections&lt;/code&gt;&lt;/h2&gt;&#xA;&lt;p&gt;You can instruct ghc to emit code in individual minimal sections, allowing the&#xA;linker to easily find and remove dead code. This looks like, in your&#xA;&lt;code&gt;cabal.project&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>GHC LLVM LTO Experiments Scratch Notes</title>
      <link>https://brandon.si/code/ghc-llvm-lto-experiments-scratch-notes/</link>
      <pubDate>Sun, 02 Jun 2019 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/ghc-llvm-lto-experiments-scratch-notes/</guid>
      <description>&lt;p&gt;*This is a followup to &lt;a href=&#34;https://brandon.si/code/initial-hacking-of-ghc-for-gcc-link-time-optimization/&#34;&gt;this previous post&lt;/a&gt;&#xA;where I play with GCC&amp;rsquo;s link-time optimization in GHC-compiled programs. I note there that this is&#xA;limited since it only works on sources compiled from C (crucially the RTS). Here I&amp;rsquo;ve compiled rough&#xA;notes doing the same thing with LLVM LTO, where I attempt to get true whole-program optimization&#xA;*cooking.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;The goals were to play with some new tech and possibly discover some significant performance gains&#xA;(without thinking very hard) that could be ported back or realized in a less hacky way.&#xA;Results were underwhelming and so I don&amp;rsquo;t do much real digging into assembly (the other thing&#xA;besides good results that would have made for an interesting post). So after waffling I decided to&#xA;basically dump my notes here, lightly edited, in case it&amp;rsquo;s helpful to someone who wants to take up&#xA;similar work later.&lt;/em&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>A little tool for visualizing ghc verbose timing</title>
      <link>https://brandon.si/code/a-little-tool-for-visualizing-ghc-verbose-timing/</link>
      <pubDate>Tue, 07 May 2019 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-little-tool-for-visualizing-ghc-verbose-timing/</guid>
      <description>&lt;p&gt;I wrote a little tool to graph the fine-grained timing logs produced by ghc&#xA;when the &lt;code&gt;-v&lt;/code&gt; (verbose) flag is given. These logs to STDERR look like, e.g.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;!!! Liberate case [Data.Binary.Class]: finished in 32.06 milliseconds, allocated 14.879 megabytes&#xA;!!! Simplifier [Data.Binary.Class]: finished in 873.97 milliseconds, allocated 563.867 megabytes&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The project is on GitHub at&#xA;&lt;a href=&#34;https://github.com/jberryman/ghc-timing-treemap&#34;&gt;jberryman/ghc-timing-treemap&lt;/a&gt;,&#xA;along with a screenshot.&lt;/p&gt;&#xA;&lt;p&gt;Navigating within the graph is pretty slow at least in firefox, and there are&#xA;some other improvements that could be made, for instance some of the phases are&#xA;run multiple times on the same module and it would be nice to see these&#xA;grouped, where the module name is logged.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Initial hacking of GHC for GCC link-time optimization</title>
      <link>https://brandon.si/code/initial-hacking-of-ghc-for-gcc-link-time-optimization/</link>
      <pubDate>Wed, 10 Apr 2019 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/initial-hacking-of-ghc-for-gcc-link-time-optimization/</guid>
      <description>&lt;p&gt;I spent some time hacking GHC to use GCC&amp;rsquo;s &lt;a href=&#34;https://en.wikipedia.org/wiki/Interprocedural_optimization&#34;&gt;link-time optimization&lt;/a&gt;,&#xA;and wanted to share the results. The idea was to see whether we could get&#xA;performance gains or other interesting results from :&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;cross module inlining, e.g. between C libraries from &lt;code&gt;base&lt;/code&gt; and the RTS&lt;/li&gt;&#xA;&lt;li&gt;GCC build flags that can only be added later, like &lt;code&gt;-march=native&lt;/code&gt; to tailor optimizations to our microarchitecture&lt;/li&gt;&#xA;&lt;li&gt;possibly nice interactions at barrier of haskell code and LTO&amp;rsquo;d C?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;This was all very speculative, and the results you see below aren&amp;rsquo;t ultimately&#xA;very interesting.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Hacking around on an FV-1 based guitar pedal</title>
      <link>https://brandon.si/code/hacking-around-on-an-fv-1-based-guitar-pedal/</link>
      <pubDate>Sat, 26 Jan 2019 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/hacking-around-on-an-fv-1-based-guitar-pedal/</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a diary-style post where I chronicle what I learn digging into a&#xA;digital guitar effects pedal for the first time. I&amp;rsquo;m not sure how useful or&#xA;interesting it will be to others.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;I picked up an oddball modulation pedal from a &amp;ldquo;boutique&amp;rdquo; maker (being coy here)&#xA;and decided there were a bunch of things I could improve about it, so I thought&#xA;I&amp;rsquo;d try to tweak it. I know almost nothing about electronics.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Choosing a binary-to-text encoding</title>
      <link>https://brandon.si/code/choosing-a-binary-to-text-encoding/</link>
      <pubDate>Sat, 22 Apr 2017 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/choosing-a-binary-to-text-encoding/</guid>
      <description>&lt;p&gt;I had an occasion to think about text-friendly binary encoding schemes for the&#xA;first time at work. The obvious choice is&#xA;&lt;a href=&#34;https://en.wikipedia.org/wiki/Base64&#34;&gt;&lt;strong&gt;Base64&lt;/strong&gt;&lt;/a&gt;, but my immediate subsequent&#xA;thought was &amp;ldquo;there must be something much more efficient for our purposes&amp;rdquo;, and a quick google led&#xA;&lt;a href=&#34;http://stackoverflow.com/questions/31817721/a-more-compact-representation-than-base64-for-byte-arrays&#34;&gt;here&lt;/a&gt;&#xA;in which OP echos the same feeling:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;It seems to me that we can greatly improve since on my keyboard I already see&#xA;94 easily distinguishable printable keys.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Almost inline ASM in haskell with foreign import prim</title>
      <link>https://brandon.si/code/almost-inline-asm-in-haskell-with-foreign-import-prim/</link>
      <pubDate>Sun, 12 Mar 2017 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/almost-inline-asm-in-haskell-with-foreign-import-prim/</guid>
      <description>&lt;p&gt;With help from Reid Barton in questions &lt;a href=&#34;http://stackoverflow.com/q/41528208/176841&#34;&gt;here&lt;/a&gt; and&#xA;&lt;a href=&#34;http://stackoverflow.com/q/41213378/176841&#34;&gt;here&lt;/a&gt; I discovered it&amp;rsquo;s pretty&#xA;easy to call assembly from GHC haskell with minimal overhead, so I cleaned up&#xA;an example of this technique and posted it here:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://github.com/jberryman/almost-inline-asm-haskell-example&#34;&gt;https://github.com/jberryman/almost-inline-asm-haskell-example&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is especially useful if you want to return multiple values from a foreign&#xA;procedure, where otherwise with the traditional FFI approach you would have to&#xA;do some allocation and stuff the values into a struct or something. I find the&#xA;above more understandable in any case.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing: unagi-bloomfilter</title>
      <link>https://brandon.si/code/announcing-unagi-bloomfilter/</link>
      <pubDate>Thu, 25 Aug 2016 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/announcing-unagi-bloomfilter/</guid>
      <description>&lt;p&gt;I just released a new Haskell library called unagi-bloomfilter that is up now&#xA;&lt;a href=&#34;https://hackage.haskell.org/package/unagi-bloomfilter&#34;&gt;on hackage&lt;/a&gt;. You can&#xA;install it with:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;$ cabal install unagi-bloomfilter&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The library uses the &lt;em&gt;bloom-1&lt;/em&gt; variant from &amp;ldquo;Fast Bloom Filters and Their&#xA;Generalization&amp;rdquo; by Yan Qiao, et al. I&amp;rsquo;ll try to write more about it when I have&#xA;the time. Also I just gave a talk on things I learned working on the project&#xA;last night at the New York Haskell User Group:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing: Hashabler 1.0. Now even more hashy with SipHash</title>
      <link>https://brandon.si/code/announcing-hashabler-1-dot-0-now-even-more-hashy-with-siphash/</link>
      <pubDate>Sun, 16 Aug 2015 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/announcing-hashabler-1-dot-0-now-even-more-hashy-with-siphash/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve just released version 1.0 of a haskell library for principled,&#xA;cross-platform &amp;amp; extensible hashing of types. It is available&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/hashabler&#34;&gt;on hackage&lt;/a&gt;, and can be&#xA;installed with:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install hashabler&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;(see my &lt;a href=&#34;https://brandon.si/code/announcing-hashabler-like-hashable/&#34;&gt;initial announcement post&lt;/a&gt;&#xA;which has some motivation and pretty pictures)&lt;/p&gt;&#xA;&lt;p&gt;You can see the &lt;a href=&#34;https://github.com/jberryman/hashabler/blob/master/CHANGELOG.markdown&#34;&gt;CHANGELOG&lt;/a&gt;&#xA;but the main change is an implementation of &lt;a href=&#34;https://131002.net/siphash/&#34;&gt;SipHash&lt;/a&gt;.&#xA;It&amp;rsquo;s about as fast as our implementation of FNV-1a for bytestrings of length&#xA;fifty and slightly faster when you get to length 1000 or so, so you should use&#xA;it unless you&amp;rsquo;re wanting a hash with a simple implementation.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Translating some stateful bit-twiddling to haskell</title>
      <link>https://brandon.si/code/translating-some-stateful-bit-twiddling-to-haskell/</link>
      <pubDate>Fri, 03 Jul 2015 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/translating-some-stateful-bit-twiddling-to-haskell/</guid>
      <description>&lt;p&gt;I just started implementing &lt;a href=&#34;https://131002.net/siphash/&#34;&gt;SipHash&lt;/a&gt; in&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/hashabler&#34;&gt;&lt;code&gt;hashabler&lt;/code&gt;&lt;/a&gt; and wanted to share&#xA;a nice way I found to translate stateful bit-twiddling code in C (which makes&#xA;heavy use of bitwise assignment operators) to haskell.&lt;/p&gt;&#xA;&lt;p&gt;I was working from the&#xA;&lt;a href=&#34;https://github.com/veorq/SipHash/blob/master/siphash24.c&#34;&gt;reference implementation&lt;/a&gt;.&#xA;As you can see statefulness and mutability are an implicit part of how the&#xA;algorithm is defined, as it modifies the states of the &lt;code&gt;v&lt;/code&gt; variables.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#define SIPROUND                                        \&#xA;  do {                                                  \&#xA;    v0 += v1; v1=ROTL(v1,13); v1 ^= v0; v0=ROTL(v0,32); \&#xA;    v2 += v3; v3=ROTL(v3,16); v3 ^= v2;                 \&#xA;    v0 += v3; v3=ROTL(v3,21); v3 ^= v0;                 \&#xA;    v2 += v1; v1=ROTL(v1,17); v1 ^= v2; v2=ROTL(v2,32); \&#xA;  } while(0)&#xA;&#xA;int  siphash( uint8_t *out, const uint8_t *in, uint64_t inlen, const uint8_t *k )&#xA;{&#xA;&#xA;  /* ... */&#xA;&#xA;  for ( ; in != end; in += 8 )&#xA;  {&#xA;    m = U8TO64_LE( in );&#xA;    v3 ^= m;&#xA;&#xA;    TRACE;&#xA;    for( i=0; i&amp;lt;cROUNDS; ++i ) SIPROUND;&#xA;&#xA;    v0 ^= m;&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I wanted to translate this sort of code as directly as possible (I&amp;rsquo;d already&#xA;decided if it didn&amp;rsquo;t work on the first try I would burn my laptop and live in&#xA;the woods, rather than debug this crap).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing hashabler: like hashable only more so</title>
      <link>https://brandon.si/code/announcing-hashabler-like-hashable/</link>
      <pubDate>Thu, 30 Apr 2015 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/announcing-hashabler-like-hashable/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve just released the first version of a haskell library for principled,&#xA;cross-platform &amp;amp; extensible hashing of types, which includes an implementation&#xA;of the FNV-1a algorithm. It is available &lt;a href=&#34;http://hackage.haskell.org/package/hashabler&#34;&gt;on hackage&lt;/a&gt;,&#xA;and can be installed with:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install hashabler&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;code&gt;hashabler&lt;/code&gt; is a rewrite of the &lt;a href=&#34;http://hackage.haskell.org/package/hashable&#34;&gt;hashable&lt;/a&gt;&#xA;library by Milan Straka and Johan Tibell, having the following goals:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Extensibility; it should be easy to implement a new hashing algorithm on any&#xA;Hashable type, for instance if one needed more hash bits&lt;/p&gt;</description>
    </item>
    <item>
      <title>Benchmarking very fast things with criterion</title>
      <link>https://brandon.si/code/benchmarking-very-fast-things-with-criterion/</link>
      <pubDate>Thu, 05 Mar 2015 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/benchmarking-very-fast-things-with-criterion/</guid>
      <description>&lt;p&gt;There&amp;rsquo;s a pervasive myth that Bryan O&amp;rsquo;Sullivan&amp;rsquo;s excellent haskell benchmarking&#xA;library &lt;a href=&#34;http://hackage.haskell.org/package/criterion&#34;&gt;criterion&lt;/a&gt; is only&#xA;useful for benchmarks that take some significant chunk of time (I&amp;rsquo;ve even heard&#xA;some people claim on the &lt;em&gt;ms&lt;/em&gt; scale). In fact criterion is useful for almost&#xA;anything you&amp;rsquo;d want to benchmark.&lt;/p&gt;&#xA;&lt;p&gt;At a high level &lt;code&gt;criterion&lt;/code&gt; makes your benchmark the inner loop of a function,&#xA;and runs that loop a bunch of times, measures the result, and then divides by&#xA;the number of iterations it performed. The approach is both useful for comparing&#xA;alternative implementations, and probably the only meaningful way of answering&#xA;&amp;ldquo;how long does this code take to run&amp;rdquo;, short of looking at the assembly and&#xA;counting the instructions and consulting your processor&amp;rsquo;s manual.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing unagi-chan</title>
      <link>https://brandon.si/code/announcing-unagi-chan/</link>
      <pubDate>Tue, 07 Oct 2014 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/announcing-unagi-chan/</guid>
      <description>&lt;p&gt;Today I released version 0.2 of &lt;code&gt;unagi-chan&lt;/code&gt;, a haskell library implementing&#xA;fast and scalable FIFO queues with a nice and familiar API.  It is&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/unagi-chan&#34;&gt;available on hackage&lt;/a&gt;&#xA;and you can install it with:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;$ cabal install unagi-chan&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This version provides a bounded queue variant (and closes&#xA;&lt;a href=&#34;https://github.com/jberryman/unagi-chan/issues/1&#34;&gt;issue #1&lt;/a&gt;!)&#xA;that has performance on par with the other variants in the library. This is&#xA;something I&amp;rsquo;m somewhat proud of, considering that the standard&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/stm-2.4.3/docs/Control-Concurrent-STM-TBQueue.html&#34;&gt;&lt;code&gt;TBQueue&lt;/code&gt;&lt;/a&gt;&#xA;is not only significantly slower than e.g. &lt;code&gt;TQueue&lt;/code&gt;, but also was seen to&#xA;livelock at a fairly low level of concurrency (and so is not included in the&#xA;benchmark suite).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Thoughts on FIFO-ness</title>
      <link>https://brandon.si/code/thoughts-on-fifo-ness/</link>
      <pubDate>Mon, 03 Feb 2014 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/thoughts-on-fifo-ness/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been doing a lot of experimenting with concurrent operations in haskell&#xA;and in particular playing with and thinking about the design of concurrent&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Queue_%28abstract_data_type%29&#34;&gt;FIFO queues&lt;/a&gt;.&#xA;These structures are difficult to make both efficient and correct,&#xA;due to the effects of contention on the parts of the structure tasked with&#xA;coordinating reads and writes from multiple threads.&lt;/p&gt;&#xA;&lt;p&gt;These are my thoughts so far on FIFO semantics.&lt;/p&gt;&#xA;&lt;h2 id=&#34;fifo-and-how&#34;&gt;FIFO? And how!&lt;/h2&gt;&#xA;&lt;p&gt;In the interesting paper&#xA;&lt;a href=&#34;http://www.cs.uni-salzburg.at/~hpayer/publications/races12.pdf&#34;&gt;&amp;ldquo;How FIFO is your concurrent FIFO queue?&amp;rdquo;&lt;/a&gt;(PDF).&#xA;A Haas, et al. propose that an ideal FIFO queue has operations that are&#xA;instantaneous (think of each &lt;code&gt;write&lt;/code&gt; having an infinitely accurate timestamp,&#xA;and each &lt;code&gt;read&lt;/code&gt; taking the corresponding element in timestamp order). They then&#xA;measure the degree to which &lt;em&gt;real&lt;/em&gt; queues of various designs deviate from this&#xA;platonic FIFO semantics in their message ordering, using a metric they call&#xA;&amp;ldquo;element-fairness&amp;rdquo;. They experimentally measure element-fairness of both&#xA;so-called &amp;ldquo;strict FIFO&amp;rdquo; as well as &amp;ldquo;relaxed FIFO&amp;rdquo; designs, in which elements&#xA;are read in more or less the order they were written (some providing guarantees&#xA;of degree of re-ordering, others not).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing shapely-data v0.1</title>
      <link>https://brandon.si/code/announcing-shapely-data-v0-dot-1/</link>
      <pubDate>Mon, 23 Dec 2013 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/announcing-shapely-data-v0-dot-1/</guid>
      <description>&lt;p&gt;This is the first &lt;em&gt;real&lt;/em&gt; release &lt;code&gt;shapely-data&lt;/code&gt;, a haskell library&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/shapely-data&#34;&gt;up here on hackage&lt;/a&gt;&#xA;for working with algebraic datatypes in a simple generic form made up of&#xA;haskell&amp;rsquo;s primitive product, sum and unit types: &lt;code&gt;(,)&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt;, and &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;You can install it with&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install shapely-data&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;h1 id=&#34;motivation-and-examples&#34;&gt;Motivation and examples&lt;/h1&gt;&#xA;&lt;p&gt;In order from most to least important to me, here are the concerns that&#xA;motivated the library:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Provide a good story for &lt;code&gt;(,)&lt;/code&gt;/&lt;code&gt;Either&lt;/code&gt; as a &lt;em&gt;lingua franca&lt;/em&gt; generic&#xA;representation that other library writers can use without dependencies,&#xA;encouraging abstractions in terms of products and sums (motivated&#xA;specifically by my work on&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/simple-actors&#34;&gt;&lt;code&gt;simple-actors&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Writing a streaming twitter waterflow solution</title>
      <link>https://brandon.si/code/writing-a-streaming-twitter-waterflow-solution/</link>
      <pubDate>Mon, 18 Nov 2013 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/writing-a-streaming-twitter-waterflow-solution/</guid>
      <description>&lt;p&gt;In &lt;a href=&#34;http://philipnilsson.github.io/Badness10k/articles/waterflow/&#34;&gt;this post&lt;/a&gt;&#xA;Philip Nilsson describes an inspiring, principled approach to solving&#xA;a toy problem posed in a programming interview. I wanted to implement a&#xA;solution to a variant of the problem where we&amp;rsquo;d like to process a stream.&#xA;It was pretty easy to sketch a solution out on paper but Philip&amp;rsquo;s solution&#xA;was invaluable in testing and debugging my implementation. (See also Chris&#xA;Done&amp;rsquo;s &lt;a href=&#34;http://chrisdone.com/posts/twitter-problem-loeb&#34;&gt;mind-melting loeb approach&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;My goal was to have a function:&lt;/p&gt;</description>
    </item>
    <item>
      <title>A TypeFamilies Primer</title>
      <link>https://brandon.si/code/a-typefamilies-primer/</link>
      <pubDate>Mon, 12 Aug 2013 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-typefamilies-primer/</guid>
      <description>&lt;p&gt;&lt;code&gt;TypeFamilies&lt;/code&gt; is a GHC extension that lets you create formerly-impossible&#xA;abstractions in a very straightforward way. It took me several tries before&#xA;they clicked for me though, so this is the introduction to &lt;code&gt;TypeFamilies&lt;/code&gt; that&#xA;I wish I had read first (although I just found &lt;a href=&#34;http://byorgey.wordpress.com/2010/07/06/typed-type-level-programming-in-haskell-part-ii-type-families/&#34;&gt;Brent Yorgey&amp;rsquo;s&lt;/a&gt;, which would have done the trick).&lt;/p&gt;&#xA;&lt;p&gt;I&amp;rsquo;m treating the subject very narrowly for most of this post, and try to round&#xA;things out a little at the very end.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Thinking about an economy of bit flips</title>
      <link>https://brandon.si/code/thinking-about-an-economy-of-bit-flips/</link>
      <pubDate>Sun, 17 Mar 2013 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/thinking-about-an-economy-of-bit-flips/</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclaimer: un-researched, under-educated, fast and loose hacking follows.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;The other day I was thinking about counting in binary and how bits cascade when&#xA;incrementing a counter.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;000&#xA;001&#xA;010&#xA;011&#xA;100&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I wondered: what if each bit flip was very &amp;ldquo;expensive&amp;rdquo;, for the hardware say?&#xA;Are there other methods we could use that woud result in a &amp;ldquo;cheaper&amp;rdquo; increment&#xA;operation, by avoiding those costly carries?&lt;/p&gt;&#xA;&lt;p&gt;First, here&amp;rsquo;s a little bit of boring code that we&amp;rsquo;ll use below to print a list&#xA;of Ints as padded binary, and some requisite imports:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Using GHC&#39;s RebindableSyntax for a dynamic state &#34;Fauxnad&#34;</title>
      <link>https://brandon.si/code/using-ghcs-rebindablesyntax-for-a-dynamic-state-fauxnad/</link>
      <pubDate>Sun, 10 Feb 2013 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/using-ghcs-rebindablesyntax-for-a-dynamic-state-fauxnad/</guid>
      <description>&lt;p&gt;I just learned about GHC&amp;rsquo;s &lt;code&gt;RebindableSyntax&lt;/code&gt; extension from&#xA;&lt;a href=&#34;http://www.reddit.com/r/haskell/comments/16zrsp/generalizing_do_notation/&#34;&gt;chrisdoner&amp;rsquo;s thread on reddit&lt;/a&gt;&#xA;and wanted to play around with scratching a couple itches I&amp;rsquo;ve had. In this&#xA;post I&amp;rsquo;ll illustrate using &lt;code&gt;RebindableSyntax&lt;/code&gt; to allow us to use haskell&amp;rsquo;s&#xA;&lt;code&gt;do&lt;/code&gt; notation in a State-monad-like construction, in which our state type is&#xA;allowed to change (I&amp;rsquo;ve played with this idea&#xA;&lt;a href=&#34;http://brandon.si/code/a-state-monad-with-dynamically-typed-state/&#34;&gt;previously&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;The dynamic state construction looks like the traditional &lt;code&gt;State&lt;/code&gt;, but with&#xA;separate types for input and output state:&lt;/p&gt;</description>
    </item>
    <item>
      <title>dilly.js: a library for loops with delays in JavaScript</title>
      <link>https://brandon.si/code/dilly-dot-js-a-library-for-loops-with-delays-in-javascript/</link>
      <pubDate>Tue, 09 Oct 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/dilly-dot-js-a-library-for-loops-with-delays-in-javascript/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve released a &lt;a href=&#34;https://github.com/jberryman/dilly.js&#34;&gt;new library&lt;/a&gt;&#xA;for writing sort of idiomatic-looking loops with delays in javascript. This was&#xA;motivated by &lt;a href=&#34;http://jberryman.github.com/fly-mis/&#34;&gt;this&lt;/a&gt;&#xA;work in which I was implementing an algorithm/simulation;&#xA;I wanted the code to be readable as straighforward loops, but I needed&#xA;a delay for the visual portion.&lt;/p&gt;&#xA;&lt;p&gt;Here is an example of its usage:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;withDelay(1000).endingWith(other_stuff)                  &#xA;    .for(&amp;quot;x&amp;quot;,1,2)                // range: 1, 2&#xA;        .for(&amp;quot;y&amp;quot;,1,3 , 8)        // range(with step of 2): 1, 3, 5, 7&#xA;            .for(&amp;quot;z&amp;quot;,[&#39;a&#39;,&#39;b&#39;])  // foreach: &#39;a&#39;, &#39;b&#39;&#xA;                .do(function(){ &#xA;                    console.log(this.var(&amp;quot;x&amp;quot;), &#xA;                                this.var(&amp;quot;y&amp;quot;), &#xA;                                this.var(&amp;quot;z&amp;quot;));&#xA;                 });&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The inner &lt;code&gt;do&lt;/code&gt; block runs with a one-second delay between executions.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Making your zipper disappear with Zippo</title>
      <link>https://brandon.si/code/making-your-zipper-disappear-with-zippo/</link>
      <pubDate>Mon, 17 Sep 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/making-your-zipper-disappear-with-zippo/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve finally had a chance to look at how my new lens-based, power-packed,&#xA;minimal zipper library &lt;a href=&#34;http://hackage.haskell.org/package/zippo-0.1&#34;&gt;zippo&lt;/a&gt;&#xA;looks when compiled, and initial results are pleasing!&lt;/p&gt;&#xA;&lt;p&gt;For example, here is a silly zipper operation that increments the nodes&#xA;of a sort-of tree:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;module Main where&#xA;&#xA;import Control.Category((&amp;gt;&amp;gt;&amp;gt;))&#xA;import Data.Lens.Zipper&#xA;import Data.Yall.Lens&#xA;&#xA;data Tree a = Br { _lBranch :: NodeBr a&#xA;                 , _rBranch :: NodeBr a }&#xA;            deriving Show&#xA;&#xA;data NodeBr a = NodeBr { _node :: a }&#xA;    deriving Show&#xA;&#xA;-- START BOILERPLATE&#xA;lBranch = lens _lBranch (\(Br _ r) l-&amp;gt; Br l r)&#xA;rBranch = lens _rBranch (\(Br l _) r-&amp;gt; Br l r)&#xA;node = lens _node $ const NodeBr&#xA;-- END BOILERPLATE&#xA;&#xA;-- example data:&#xA;t = Br (NodeBr 1 ) (NodeBr 3 )&#xA;&#xA;-- zipper operations&#xA;incNode = moveP node &amp;gt;&amp;gt;&amp;gt; modf (+1) &amp;gt;&amp;gt;&amp;gt; moveUp&#xA;zops = zipper &amp;gt;&amp;gt;&amp;gt; moveP lBranch &amp;gt;&amp;gt;&amp;gt; incNode &amp;gt;&amp;gt;&amp;gt; moveUp &amp;gt;&amp;gt;&amp;gt; &#xA;        moveP rBranch &amp;gt;&amp;gt;&amp;gt; incNode &amp;gt;&amp;gt;&amp;gt; close&#xA;&#xA;main = print $ zops t&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When compiled with&lt;/p&gt;</description>
    </item>
    <item>
      <title>simple-actors 0.4.0: a few interesting design bits</title>
      <link>https://brandon.si/code/simple-actors-0-dot-4-0-a-few-interesting-design-bits/</link>
      <pubDate>Wed, 22 Aug 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/simple-actors-0-dot-4-0-a-few-interesting-design-bits/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://hackage.haskell.org/package/simple-actors&#34;&gt;simple-actors&lt;/a&gt;&#xA;is my library for more structured concurrent programming based&#xA;on the &lt;a href=&#34;http://en.wikipedia.org/wiki/Actor_model&#34;&gt;Actor model&lt;/a&gt;.&#xA;It&amp;rsquo;s been a fun vehicle for exploring concurrent&#xA;semantics, and an opportunity to solve some tricky API design problems in&#xA;pretty clever ways. I want to present a handful of these problems, and the&#xA;solutions I came up with, below.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Short digression:&lt;/em&gt; I love distributed systems, but this library has nothing to&#xA;do with distributed programming. Also performance.&lt;/p&gt;</description>
    </item>
    <item>
      <title>zippo: a lightweight lens-based, type-checked, heterogenous zipper</title>
      <link>https://brandon.si/code/zippo/</link>
      <pubDate>Mon, 28 May 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/zippo/</guid>
      <description>&lt;p&gt;I finished this new &lt;a href=&#34;http://hackage.haskell.org/package/zippo&#34;&gt;zipper library&lt;/a&gt;&#xA;which you can get with a&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install zippo&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and &lt;a href=&#34;https://github.com/jberryman/zippo&#34;&gt;fork it on github&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;After working for a long time on &lt;a href=&#34;http://hackage.haskell.org/package/pez&#34;&gt;pez&lt;/a&gt;,&#xA;I wanted to try a zipper library that was also based on lenses, but where&#xA;heterogenous move up operations would be type-checked, as would a move up&#xA;past the &amp;ldquo;top&amp;rdquo; of the structure.&lt;/p&gt;&#xA;&lt;p&gt;It looks as though &lt;a href=&#34;http://hackage.haskell.org/package/instant-zipper&#34;&gt;instant-zipper&lt;/a&gt;&#xA;is the only other zipper package that provides that kind of type safety.&lt;/p&gt;</description>
    </item>
    <item>
      <title>A Simulation of a Biological MIS Algorithm</title>
      <link>https://brandon.si/code/a-simulation-of-a-biological-mis-algorithm/</link>
      <pubDate>Mon, 14 May 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-simulation-of-a-biological-mis-algorithm/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve finished a simulation-visualization of the very cool algorithm for&#xA;generating a&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Maximal_independent_set&#34;&gt;Maximal Independant Set&lt;/a&gt;&#xA;from &amp;ldquo;A Biological Solution to a Fundamental Distributed Computing Problem&amp;rdquo; by&#xA;Afek et al. (sorry I don&amp;rsquo;t have a link to the PDF, and respect you too much to&#xA;link you to a paywall).&lt;/p&gt;&#xA;&lt;p&gt;You can &lt;a href=&#34;http://jberryman.github.com/fly-mis/&#34;&gt;play with it&lt;/a&gt;&#xA;or &lt;a href=&#34;https://github.com/jberryman/fly-mis&#34;&gt;check out the code&lt;/a&gt; on GitHub;&#xA;in particular, see&#xA;&lt;a href=&#34;https://github.com/jberryman/fly-mis/blob/master/algorithm.js&#34;&gt;&amp;ldquo;algorithm.js&amp;rdquo;&lt;/a&gt;&#xA;for the didactic implementation of the algorithm.&lt;/p&gt;&#xA;&lt;p&gt;It uses jQuery and &lt;a href=&#34;http://raphaeljs.com&#34;&gt;Raphael.js&lt;/a&gt; for the visuals and&#xA;events.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Converting HTML5 canvas elements to images</title>
      <link>https://brandon.si/code/converting-html5-canvas-elements-to-images/</link>
      <pubDate>Mon, 30 Apr 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/converting-html5-canvas-elements-to-images/</guid>
      <description>&lt;p&gt;I recently needed to do some conversions/processing to a bunch of HTML files,&#xA;which contained html &lt;a href=&#34;http://en.wikipedia.org/wiki/Canvas_element&#34;&gt;canvas&lt;/a&gt;&#xA;images, so I needed a way of converting all the canvas elements on the page to&#xA;PNGs.&lt;/p&gt;&#xA;&lt;p&gt;After a bit of research and tweaking, the following worked well enough for me:&lt;/p&gt;&#xA;&lt;p&gt;{% gist 2561736 %}&lt;/p&gt;&#xA;&lt;p&gt;Run it in your browser&amp;rsquo;s JS console on the page you want to process (we assume&#xA;jQuery is already loaded on the page).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Announcing yet another lens library</title>
      <link>https://brandon.si/code/yall/</link>
      <pubDate>Wed, 04 Apr 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/yall/</guid>
      <description>&lt;p&gt;I just uploaded the first version of a lens library I&amp;rsquo;ve been working on, called&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/yall&#34;&gt;yall&lt;/a&gt;. You can get it with a&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install yall&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;or check it out &lt;a href=&#34;https://github.com/jberryman/yall&#34;&gt;on github&lt;/a&gt;. There will be a&#xA;Template Haskell library for automatically deriving lenses at some point in the&#xA;future.&lt;/p&gt;&#xA;&lt;p&gt;I was motivated primarily by the desire for a lens that is acceptable for&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/pez&#34;&gt;pez&lt;/a&gt; (existing libs  such as the&#xA;excellent &lt;a href=&#34;http://hackage.haskell.org/package/fclabels&#34;&gt;fclabels&lt;/a&gt;&#xA;or &lt;a href=&#34;http://hackage.haskell.org/package/data-lens&#34;&gt;data-lens&lt;/a&gt;&#xA;didn&amp;rsquo;t fit the bill for assorted reasons), and&#xA;to explore some abstractions and generalizations re lenses more deeply.&lt;/p&gt;</description>
    </item>
    <item>
      <title>the Monoid instance for Ordering</title>
      <link>https://brandon.si/code/the-monoid-instance-for-ordering/</link>
      <pubDate>Mon, 02 Apr 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-monoid-instance-for-ordering/</guid>
      <description>&lt;p&gt;I was just looking at the &lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Monoid.html&#34;&gt;Monoid&lt;/a&gt;&#xA;docs, when I found an instance that surprised me: &lt;code&gt;Ordering&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Here is how it&amp;rsquo;s defined:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;-- lexicographical ordering&#xA;instance Monoid Ordering where&#xA;        mempty         = EQ&#xA;        LT `mappend` _ = LT&#xA;        EQ `mappend` y = y&#xA;        GT `mappend` _ = GT&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Without the comment I don&amp;rsquo;t know if I would have gotten it right away, but&#xA;check this out:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Prelude&amp;gt; :m + Data.Monoid &#xA;Prelude Data.Monoid&amp;gt; zipWith compare &amp;quot;asff&amp;quot; &amp;quot;asdf&amp;quot;&#xA;[EQ,EQ,GT,EQ]&#xA;Prelude Data.Monoid&amp;gt; let compare&#39; s = mconcat . zipWith compare s&#xA;Prelude Data.Monoid&amp;gt; compare&#39; &amp;quot;asff&amp;quot; &amp;quot;asdf&amp;quot;&#xA;GT&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;A string comparison function can be defined using the comparisons of&#xA;corresponding letters (, numbers, etc.) as Monoids.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Optimization fun: Minimum Edit Distance</title>
      <link>https://brandon.si/code/optimization-fun-minimum-edit-distance/</link>
      <pubDate>Tue, 20 Mar 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/optimization-fun-minimum-edit-distance/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m doing Stanford&amp;rsquo;s free online [NLP class](NLP class),&#xA;and last week&amp;rsquo;s lesson introduced&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Levenshtein_distance&#34;&gt;Levenshtein Distance&lt;/a&gt;&#xA;and the traditional matrix-based algorithm. I implemented&#xA;the algorithm in haskell to get a better understanding of it, but then got a bit&#xA;obsessive about optimizing.&lt;/p&gt;&#xA;&lt;p&gt;I wanted to develop an approach iteratively so I&amp;rsquo;d learn something along the way,&#xA;but I didn&amp;rsquo;t take great pains to document the process very well, nor do I have any&#xA;analysis here of low level details.&lt;/p&gt;</description>
    </item>
    <item>
      <title>shapely-data: a library for structuralizing Haskell data types</title>
      <link>https://brandon.si/code/shapely-data/</link>
      <pubDate>Tue, 06 Mar 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/shapely-data/</guid>
      <description>&lt;p&gt;This was a quick, on-a-whim sort of project that ended up taking me all week,&#xA;as I learned my way around&#xA;&lt;a href=&#34;http://www.haskell.org/ghc/docs/7.0.2/html/users_guide/template-haskell.html&#34;&gt;template haskell&lt;/a&gt;.&#xA;It felt like trying to make a sandwich with your feet for the first time, and&#xA;was about as traumatizing.&lt;/p&gt;&#xA;&lt;p&gt;Anyway the result is my library named&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/shapely-data&#34;&gt;shapely-data&lt;/a&gt;&#xA;which you can get with the usual&amp;hellip;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install shapely-data&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and is up on github &lt;a href=&#34;https://github.com/jberryman/shapely-data&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The library can be used to convert an algebraic data type into a form that&#xA;replaces its constructors with a combination of &lt;code&gt;(,)&lt;/code&gt;, &lt;code&gt;Either&lt;/code&gt; and &lt;code&gt;()&lt;/code&gt;. See&#xA;the haddocks for usage information, and implementation details.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Categories that want to be Arrows</title>
      <link>https://brandon.si/code/categories-that-want-to-be-arrows/</link>
      <pubDate>Sat, 11 Feb 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/categories-that-want-to-be-arrows/</guid>
      <description>&lt;p&gt;This is me recording some half-formed thoughts that have been rattling around&#xA;in my head for the last week. They concern haskell&amp;rsquo;s&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Arrow.html&#34;&gt;Arrow&lt;/a&gt;&#xA;typeclass; in particular it&amp;rsquo;s frustrating inability to be applied to types that&#xA;are in &lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Category.html&#34;&gt;Category&lt;/a&gt;&#xA;but have no suitable implementation for &lt;code&gt;arr&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Consider something as simple as:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;newtype Bij a b = Bij (a -&amp;gt; b) (b -&amp;gt; a)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;a &lt;code&gt;Category&lt;/code&gt; instance is trivial, but an &lt;code&gt;Arrow&lt;/code&gt; instance is impossible, since&#xA;we would need to supply a &lt;code&gt;b -&amp;gt; a&lt;/code&gt; given only a &lt;code&gt;a -&amp;gt; b&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>How the Haskell Prelude avoids overlapping instances in Show</title>
      <link>https://brandon.si/code/how-the-haskell-prelude-avoids-overlapping-types-in-show/</link>
      <pubDate>Mon, 06 Feb 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/how-the-haskell-prelude-avoids-overlapping-types-in-show/</guid>
      <description>&lt;p&gt;In reading about overlapping instances in haskell, I came across &lt;a href=&#34;http://hackage.haskell.org/trac/haskell-prime/wiki/OverlappingInstances&#34;&gt;this&lt;/a&gt;&#xA;proposal that mentioned that:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;[Overlapping types] can sometimes be simulated with the extra-method trick&#xA;used in the Show class of the Prelude for showing lists of characters&#xA;differently than lists of other things.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I&amp;rsquo;d never thought about how haskell-98 can support a &lt;code&gt;show &amp;quot;asdf&amp;quot;&lt;/code&gt; that returns&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&amp;quot;\&amp;quot;asdf\&amp;quot;&amp;quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;while &lt;code&gt;show [1,2,3,4]&lt;/code&gt; returns&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&amp;quot;[1,2,3,4]&amp;quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And I was surprised at the complexity of &lt;code&gt;Show&lt;/code&gt; when I looked at the &lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#t:Show&#34;&gt;docs&lt;/a&gt; and&#xA;implementation (to be honest, I had no idea how the class was implemented or&#xA;that &lt;code&gt;show&lt;/code&gt; was not the only method).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Haskell state of the Lens, etc.</title>
      <link>https://brandon.si/code/haskell-state-of-the-lens/</link>
      <pubDate>Tue, 31 Jan 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/haskell-state-of-the-lens/</guid>
      <description>&lt;p&gt;For my own purposes, I wanted to take a tour of all the various formulations of&#xA;lenses on hackage and thought I would post the lightly-curated results here. I&#xA;just grepped the package list page for the following terms: lens, label,&#xA;record, accessor, editor, and reference.  Some were not sufficiently general to&#xA;include here.&lt;/p&gt;&#xA;&lt;p&gt;Here were the ones implementing &amp;ldquo;lens-like&amp;rdquo; functionality, loosely in order of&#xA;my opinion on their usefulness for my own purposes:&lt;/p&gt;</description>
    </item>
    <item>
      <title>pez v0.1.0 released</title>
      <link>https://brandon.si/code/pez-v0-dot-1-0-released/</link>
      <pubDate>Sun, 29 Jan 2012 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/pez-v0-dot-1-0-released/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/pez/0.1.0/doc/html/Data-Label-Zipper.html&#34;&gt;pez&lt;/a&gt;&#xA;is a powerful, generic zipper library that can be used with a minimum of&#xA;boilerplate, using &lt;a href=&#34;http://hackage.haskell.org/package/fclabels&#34;&gt;fclabels&lt;/a&gt;&#xA;lenses as an interface. This new version supports fclabels 1.0 and uses the new&#xA;lenses supporting failure.&lt;/p&gt;&#xA;&lt;p&gt;The API has changed significantly, but should be more stable at this point. You&#xA;can try it with a:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;$ cabal install pez&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;You can find the code on github &lt;a href=&#34;https://github.com/jberryman/pez&#34;&gt;here&lt;/a&gt;. I&#xA;will try to post some fun examples here in the next week or two.&lt;/p&gt;</description>
    </item>
    <item>
      <title>simple-actors 0.1.0 released</title>
      <link>https://brandon.si/code/simple-actors-0-1-0-released/</link>
      <pubDate>Tue, 11 Oct 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/simple-actors-0-1-0-released/</guid>
      <description>&lt;p&gt;Just a quick announcement of the release of&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/simple-actors/0.1.0/doc/html/Control-Concurrent-Actors.html&#34;&gt;simple-actors&lt;/a&gt;,&#xA;a DSL-style haskell&#xA;library for more structured concurrent programs via the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Actor_model&#34;&gt;Actor Model&lt;/a&gt;. You can fork it on&#xA;&lt;a href=&#34;https://github.com/jberryman/simple-actors&#34;&gt;github&lt;/a&gt;, and install it via cabal&#xA;with a&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cabal install simple-actors&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This version is significantly more coherent, powerful and simple than the&#xA;original 0.0.1 version (which was something I just whipped together for a blog&#xA;post I haven&amp;rsquo;t gotten around to writing yet).&lt;/p&gt;&#xA;&lt;p&gt;Let me know if you have any comments or suggestions!&lt;/p&gt;</description>
    </item>
    <item>
      <title>A brief tutorial-introduction to &#39;fclabels&#39; 1.0</title>
      <link>https://brandon.si/code/a-brief-tutorial-introduction-to-fclabels-1-0/</link>
      <pubDate>Sun, 21 Aug 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-brief-tutorial-introduction-to-fclabels-1-0/</guid>
      <description>&lt;p&gt;Sebastiaan Visser et al. last week announced the release of v1.0 of&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/fclabels&#34;&gt;fclabels&lt;/a&gt;. This is a short&#xA;introduction to the changes for people who are already somewhat familiar with&#xA;the package.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;Que?&lt;/strong&gt; The fclabels package is a haskell library providing &amp;ldquo;first class&#xA;labels&amp;rdquo; for haskell data types and some Template Haskell code for&#xA;automatically generating said labels. This makes for a more composable and&#xA;much more powerful alternative to haskell&amp;rsquo;s built-in record syntactic sugar.&#xA;&lt;a href=&#34;http://blog.ezyang.com/2010/04/inessential-guide-to-fclabels/&#34;&gt;Here&lt;/a&gt; is a&#xA;good introductory tutorial.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Module &#39;chan-split&#39; released</title>
      <link>https://brandon.si/code/module-chan-split-released/</link>
      <pubDate>Sun, 17 Jul 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/module-chan-split-released/</guid>
      <description>&lt;h2 id=&#34;whaa&#34;&gt;Whaa?&lt;/h2&gt;&#xA;&lt;p&gt;chan-split is a haskell library that is a wrapper around&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Concurrent-Chan.html&#34;&gt;&lt;code&gt;Control.Concurrent.Chan&lt;/code&gt;&lt;/a&gt;s&#xA;that separates a Chan into a readable side and&#xA;a writable side.&lt;/p&gt;&#xA;&lt;p&gt;We also provide two other modules: &lt;code&gt;Data.Cofunctor&lt;/code&gt; (because there didn&amp;rsquo;t seem&#xA;to be one anywhere), and &lt;code&gt;Control.Concurrent.Chan.Class&lt;/code&gt;. The latter creates&#xA;two classes: &lt;code&gt;ReadableChan&lt;/code&gt; and &lt;code&gt;WritableChan&lt;/code&gt;, making the fundamental chan&#xA;functions polymorphic, and defining an instance for standard &lt;code&gt;Chan&lt;/code&gt; as well as&#xA;&lt;code&gt;MVar&lt;/code&gt; (an MVar is a singleton bounded channel, wanna fight about it?).&lt;/p&gt;</description>
    </item>
    <item>
      <title>simple-actors: a simple Actor Model concurrency library</title>
      <link>https://brandon.si/code/simple-actors-a-simple-actor-model-concurrency-library/</link>
      <pubDate>Mon, 30 May 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/simple-actors-a-simple-actor-model-concurrency-library/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I&amp;rsquo;ve just released&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/simple-actors/0.1.0/doc/html/Control-Concurrent-Actors.html&#34;&gt;version 0.1.0&lt;/a&gt;&#xA;of this library. It is a&#xA;complete re-write / re-think that I think makes the library much more&#xA;attractive, simple and powerful. There won&amp;rsquo;t be any more dramatic API changes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I was in need of a simple, tight library implementing the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Actor_model&#34;&gt;Actor Model of concurrency&lt;/a&gt; and didn&amp;rsquo;t find one on&#xA;hackage, so I wrote my own. You can check out the docs&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/simple-actors-0.0.1&#34;&gt;here&lt;/a&gt; and get it with&#xA;a&lt;/p&gt;</description>
    </item>
    <item>
      <title>Magic Haskell code completions in Vim!</title>
      <link>https://brandon.si/code/magic-haskell-code-completions-in-vim/</link>
      <pubDate>Sat, 07 May 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/magic-haskell-code-completions-in-vim/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: This project is on hold for now. Many people have pointed out&#xA;that the snipMate VIM plugin can probably handle many of these completions. I&#xA;may make a collection of those at some point, but I no longer have much&#xA;interest in finishing this.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I&amp;rsquo;m trying something new: putting code-in-progress up on github while I work&#xA;on it. So! I love haskell so freaking much I&amp;rsquo;ve started creating a vimscript&#xA;to improve the &lt;em&gt;typeability&lt;/em&gt; of the language in the vim editor, and the&#xA;working name is:&#xA;&lt;a href=&#34;https://github.com/jberryman/haskomplete.vim&#34;&gt;haskomplete.vim&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>PEZ: the Potentially-Excellent Zipper library release</title>
      <link>https://brandon.si/code/pez-zipper-library-released/</link>
      <pubDate>Tue, 19 Apr 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/pez-zipper-library-released/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m happy to announce the release of a&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/pez&#34;&gt;zipper library I named&lt;strong&gt;PEZ&lt;/strong&gt;&lt;/a&gt;! I&amp;rsquo;ve been learning and&#xA;building this silly library almost as long as I&amp;rsquo;ve been learning haskell. It&amp;rsquo;s&#xA;not as great as it could be, but I&amp;rsquo;m releasing it now because it&amp;rsquo;s about time.&lt;/p&gt;&#xA;&lt;p&gt;You can check it out with a:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;code&gt;cabal install pez&lt;/code&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The library provides a generic&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Zipper&#34;&gt;zipper&lt;/a&gt; that can be used on all&#xA;types in the Typeable class, for which the user defines (or generates) lenses&#xA;from the excellent &lt;a href=&#34;http://hackage.haskell.org/package/fclabels&#34;&gt;fclabels&lt;/a&gt;&#xA;package.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Synchronized Concurrent IO Actions</title>
      <link>https://brandon.si/code/synchronized-concurrent-io-actions/</link>
      <pubDate>Thu, 24 Feb 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/synchronized-concurrent-io-actions/</guid>
      <description>&lt;p&gt;This is a bit of literate haskell code that works through a system for&#xA;running concurrent IO computations that are synchronized on a stream. So we&#xA;have many &amp;ldquo;nodes&amp;rdquo; of the type &lt;code&gt;:: a -&amp;gt; IO ()&lt;/code&gt; running concurrently on a single&#xA;stream, where we would like each node to wait until all nodes have processed a&#xA;stream element before any are allowed to proceed onto the next element.&lt;/p&gt;&#xA;&lt;p&gt;This was motivated by the desire to simulate a system in which many nodes are&#xA;interacting independently according to a time-synchronized algorithm. So the&#xA;&amp;ldquo;stream&amp;rdquo; the nodes process is time.&lt;/p&gt;</description>
    </item>
    <item>
      <title>When is it okay to &#39;fail&#39;?</title>
      <link>https://brandon.si/code/when-is-it-okay-to-fail/</link>
      <pubDate>Wed, 16 Feb 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/when-is-it-okay-to-fail/</guid>
      <description>&lt;p&gt;That&amp;rsquo;s the question.&lt;/p&gt;&#xA;&lt;p&gt;In designing a couple libraries the question of the proper use of the &lt;code&gt;Monad&lt;/code&gt;&#xA;class&amp;rsquo;s &lt;code&gt;fail&lt;/code&gt; method has come up more than once.&lt;/p&gt;&#xA;&lt;p&gt;On the one hand, many people consider &lt;code&gt;fail&lt;/code&gt; to be a wart on the face of an&#xA;otherwise pure implementation of an elegant construction&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Monad_%28category_theory%29&#34;&gt;borrowed from category theory&lt;/a&gt;.&#xA;It&amp;rsquo;s as if someone defined scissors as&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&amp;ldquo;two metal blades with handles, attached by a pivot&amp;hellip; plus a bandaid in&#xA;case you cut yourself&amp;rdquo;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>New version of directory-tree on hackage</title>
      <link>https://brandon.si/code/new-version-of-directory-tree-on-hackage/</link>
      <pubDate>Sun, 13 Feb 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/new-version-of-directory-tree-on-hackage/</guid>
      <description>&lt;p&gt;In response to a request and my own review I&amp;rsquo;ve modified my&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/directory-tree&#34;&gt;directory-tree&lt;/a&gt; package as follows:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;Eq and Ord instances now compare on free &amp;ldquo;contents&amp;rdquo; type variable&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;we provide &lt;code&gt;equalShape&lt;/code&gt; function for comparison of shape and filenames&#xA;of arbitrary trees (ignoring free &amp;ldquo;contents&amp;rdquo; variable)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;provide a comparingShape used in sortDirShape&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;provide a &lt;code&gt;sortDirShape&lt;/code&gt; function that sorts a tree, taking into account&#xA;the free file &amp;ldquo;contents&amp;rdquo; data&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Now that equality and comparison functions that ignore the contents of Files&#xA;are out of the Eq and Ord instances, we can make those types of comparisons on&#xA;DirTrees of different types.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Do Applicative Functors generalize the S &amp; K Combinators?</title>
      <link>https://brandon.si/code/do-applicative-functors-generalize-the-s-k-combinators/</link>
      <pubDate>Sun, 02 Jan 2011 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/do-applicative-functors-generalize-the-s-k-combinators/</guid>
      <description>&lt;p&gt;If the title hasn&amp;rsquo;t scared you off yet, here&amp;rsquo;s the story: I was hacking on&#xA;someone else&amp;rsquo;s &lt;a href=&#34;http://hackage.haskell.org/package/fclabels-0.11.1.1&#34;&gt;code&lt;/a&gt; on&#xA;the plane and trying to wrap my head around some&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Applicative.html#t:Applicative&#34;&gt;&lt;code&gt;Applicative&lt;/code&gt; class&lt;/a&gt;&#xA;code; in particular the code in&#xA;question used the Applicative instance for &lt;code&gt;((-&amp;gt;) a)&lt;/code&gt; i.e. functions. This&#xA;turned my brain to cream-of-wheat and I had to take a break.&lt;/p&gt;&#xA;&lt;p&gt;If you aren&amp;rsquo;t familiar with &lt;strong&gt;Applicative Functors&lt;/strong&gt;, they are somewhere in&#xA;between the familiar and simple &lt;code&gt;Functor&lt;/code&gt; class and the &lt;code&gt;Monad&lt;/code&gt; class; an&#xA;abstraction for function application with a context. Check out&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Applicative_functor&#34;&gt;here&lt;/a&gt; for more.  Away&#xA;from the computer I got out a pad of paper and went about trying to figure out&#xA;how the &lt;code&gt;&amp;lt;*&amp;gt;&lt;/code&gt; method was defined over functions. Here are the types:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Working with Template Haskell in GHCi</title>
      <link>https://brandon.si/code/working-with-template-haskell-in-ghci/</link>
      <pubDate>Tue, 14 Dec 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/working-with-template-haskell-in-ghci/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve just started trying to learn and debug&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Template_Haskell&#34;&gt;Template Haskell&lt;/a&gt; and found it a&#xA;bit rough trying to explore TH interactively, but a couple of things have&#xA;helped.&lt;/p&gt;&#xA;&lt;p&gt;First and most obvious, we can use runQ to see the abstract TH syntax which a&#xA;quasi-quoted expression expands to:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Prelude&amp;gt; :set -XTemplateHaskell&#xA;Prelude&amp;gt; :m + Language.Haskell.TH&#xA;Prelude Language.Haskell.TH&amp;gt; runQ [| \a -&amp;gt; a+1 |]&#xA;LamE [VarP a_1] (InfixE (Just (VarE a_1)) (VarE GHC.Num.+) (Just (LitE (IntegerL 1))))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The second thing that was really helpful to me was turning on the &lt;em&gt;dump-&#xA;splices&lt;/em&gt; debugging option which causes GHC to print the expansions of all&#xA;&lt;code&gt;$(top-level splices)&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>A State Monad with dynamically-typed state</title>
      <link>https://brandon.si/code/a-state-monad-with-dynamically-typed-state/</link>
      <pubDate>Thu, 09 Dec 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-state-monad-with-dynamically-typed-state/</guid>
      <description>&lt;p&gt;Haskell&amp;rsquo;s&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-State-Lazy.html&#34;&gt;standard State monad types&lt;/a&gt; allow the programmer to define a computation&#xA;that works with some state in a way that looks and feels similar to using&#xA;mutable state in an imperative language. However these State monad types are&#xA;limited in that &lt;em&gt;the type of the state cannot change&lt;/em&gt; during the computation.&lt;/p&gt;&#xA;&lt;p&gt;Normally this is fine, but what if we really wanted to use the mechanics of a&#xA;state monad to pass some state value that changed type, e.g. some mutually-&#xA;recursive tree structure we would like to traverse?:&lt;/p&gt;</description>
    </item>
    <item>
      <title>New version of &#39;thrist&#39; package released</title>
      <link>https://brandon.si/code/new-version-of-thrist-package-released/</link>
      <pubDate>Sat, 13 Nov 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/new-version-of-thrist-package-released/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been collaborating with Gabor Greif on a&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/thrist&#34;&gt;new version of his &amp;rsquo;thrist&amp;rsquo; module&lt;/a&gt;,&#xA;which was just released&#xA;last night! I approached Gabor with some new ideas that came to me as I was&#xA;writing a module that uses Thrists heavily, and he invited me to co-author&#xA;this version. (See below for a brief explanation of Thrists).&lt;/p&gt;&#xA;&lt;p&gt;I noticed that in the previous version, the function &lt;code&gt;foldThrist&lt;/code&gt; was&#xA;essentially a &lt;code&gt;foldr&lt;/code&gt; with a type signature that was overly restrictive.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Designing a Module for Combinatory Logic in Haskell</title>
      <link>https://brandon.si/code/designing-a-module-for-combinatory-logic-in-haskell/</link>
      <pubDate>Sat, 04 Sep 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/designing-a-module-for-combinatory-logic-in-haskell/</guid>
      <description>&lt;p&gt;Like the &lt;a href=&#34;http://en.wikipedia.org/wiki/Lambda_calculus&#34;&gt;Lambda Calculus&lt;/a&gt; (on&#xA;which Lisp is based), Combinatory Logic is a formal system that can be used to&#xA;model and study computation. What makes it fascinating is that it is as&#xA;powerful as the (already simple) lambda calculus, but has no need for the&#xA;variables that LC requires to perform substitution!&lt;/p&gt;&#xA;&lt;p&gt;Here I show how we can use Haskell&amp;rsquo;s type classes and other language features&#xA;to model the Combinator Calculus. The goals of this module were:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Repairing NetbookInstaller&#39;s Chameleon Bootloader</title>
      <link>https://brandon.si/code/repairing-netbookinstallers-chameleon-bootloader/</link>
      <pubDate>Fri, 27 Aug 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/repairing-netbookinstallers-chameleon-bootloader/</guid>
      <description>&lt;p&gt;If you have set up your hackintosh using Meklort&amp;rsquo;s&#xA;&lt;a href=&#34;http://code.google.com/p/netbook-installer/&#34;&gt;NetbookBootMaker / NetbookInstaller&lt;/a&gt; and have&#xA;overwritten the Chameleon bootloader with&#xA;&lt;a href=&#34;http://www.gnu.org/software/grub/&#34;&gt;GRUB&lt;/a&gt; or have otherwise damaged your MBR,&#xA;you can use some of the following techniques to fix your issues.&lt;/p&gt;&#xA;&lt;p&gt;NetbookInstaller uses a custom version of&#xA;&lt;a href=&#34;http://chameleon.osx86.hu/&#34;&gt;Chameleon&lt;/a&gt; to patch the Mac OS kernel in memory&#xA;during bootup. If you have accidentally installed GRUB (or another bootloader)&#xA;to your MBR, you will probably find it is impossible to boot into your OS X&#xA;partition.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: some Simulated Annealing updates</title>
      <link>https://brandon.si/code/17x17-some-simulated-annealing-updates/</link>
      <pubDate>Sat, 31 Jul 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-some-simulated-annealing-updates/</guid>
      <description>&lt;p&gt;Note: this is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the&#xA;&amp;ldquo;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;rdquo;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Just a few follow-ups to my previous&#xA;&lt;a href=&#34;https://brandon.si/code/17x17-a-simulated-annealing-approach-using-thresholds/&#34;&gt;post in which I use a simulated annealing-type algorithm&lt;/a&gt; to find a good (hopefully&#xA;complete) cover of a grid by swapping rows and columns from four identical&#xA;sub-grids of 74 colors.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Gift of Inconsistency </title>
      <link>https://brandon.si/code/the-gift-of-inconsistency/</link>
      <pubDate>Thu, 22 Jul 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-gift-of-inconsistency/</guid>
      <description>&lt;p&gt;Computer science is a fascinating and maddening thing. Even the most&#xA;seemingly-esoteric topics turn out to be fundamental. Go out to the fringes of&#xA;CS and you find yourself smack in the middle of&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/G%C3%B6del%27s_incompleteness_theorems#Minds_and_machines&#34;&gt;Philosophy&lt;/a&gt;. You&#xA;try to understand a single point and you suddenly find yourself embracing&#xA;everything.&lt;/p&gt;&#xA;&lt;p&gt;So this post comes from that infinitely-recursive rabbit hole of wikipedia&#xA;topics I&amp;rsquo;ve been falling down for the last few weeks, and you can probably&#xA;expect a few more like this one; I&amp;rsquo;ll try to keep focused.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: A Simulated Annealing approach using thresholds</title>
      <link>https://brandon.si/code/17x17-a-simulated-annealing-approach-using-thresholds/</link>
      <pubDate>Sat, 10 Jul 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-a-simulated-annealing-approach-using-thresholds/</guid>
      <description>&lt;p&gt;Note: this is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the&#xA;&amp;ldquo;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;rdquo;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;This is something I&amp;rsquo;ve been wanting to play with for months now, but haven&amp;rsquo;t&#xA;made the time to implement: I wondered if&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Simulated_annealing&#34;&gt;simulated annealing&lt;/a&gt; techniques could&#xA;be effective in finding a complete grid covering.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Further Thoughts &amp; Some Pretty Pictures</title>
      <link>https://brandon.si/code/17x17-further-thoughts-some-pretty-pictures/</link>
      <pubDate>Tue, 01 Jun 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-further-thoughts-some-pretty-pictures/</guid>
      <description>&lt;p&gt;Note: this is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the&#xA;&amp;ldquo;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;rdquo;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;An almost silly amount of time passes between my new ideas on this problem and&#xA;investigating/coding those ideas, but I&amp;rsquo;m trying to be better about helping my&#xA;thoughts see the light of day before I get entirely bored of them.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Befunge-93 Interpreter on Hackage</title>
      <link>https://brandon.si/code/befunge-93-interpreter-on-hackage/</link>
      <pubDate>Thu, 20 May 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/befunge-93-interpreter-on-hackage/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve fixed a bug related to upgrading GHC to version 6.12 (thanks to Cale and&#xA;the folks on haskell-cafe who helped me with the issue) and got my&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Befunge&#34;&gt;Befunge-93&lt;/a&gt; interpreter up on hackage.&#xA;The program is written in haskell (as usual). You should be able to get it&#xA;soon with a:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;$ cabal install Befunge93&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If you want to read about how I designed it you can check out the source&#xA;above, or take a look at my&#xA;&lt;a href=&#34;https://brandon.si/code/a-befunge-93-interpreter/&#34;&gt;previous blog post&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Code Jam 2010: Incrementing a Binary Counter</title>
      <link>https://brandon.si/code/code-jam-2010-incrementing-a-binary-counter/</link>
      <pubDate>Sun, 09 May 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/code-jam-2010-incrementing-a-binary-counter/</guid>
      <description>&lt;h3 id=&#34;the-problem&#34;&gt;The Problem&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&#34;http://code.google.com/codejam/contest/dashboard?c=433101#s=p0&#34;&gt;Problem A&lt;/a&gt; in&#xA;the qualifying round of this year&amp;rsquo;s Google CodeJam contest was really clever.&#xA;The problem used a classic made-for-TV gadget from the 80s:&#xA;&lt;a href=&#34;http://www.youtube.com/watch?v=-XUOhjW2AXM&#34;&gt;The Clapper™&lt;/a&gt; (&amp;ldquo;snapper&amp;rdquo; in google&amp;rsquo;s&#xA;version) and went like this:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The Snapper is a clever little device that, on one side, plugs its input&#xA;plug into an output socket, and, on the other side, exposes an output socket&#xA;for plugging in a light or other device.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Some Attempts at Doubly-Symmetrical Rotations</title>
      <link>https://brandon.si/code/17x17-some-attempts-at-doubly-symmetrical-rotations/</link>
      <pubDate>Fri, 09 Apr 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-some-attempts-at-doubly-symmetrical-rotations/</guid>
      <description>&lt;p&gt;Note: this is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the &amp;quot;&#xA;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;quot;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;In a &lt;a href=&#34;https://brandon.si/code/17x17-symmetric-single-colorings-and-some-graph-theory/&#34;&gt;previous post&lt;/a&gt;&#xA;I presented rotations of some single-color rectangle-free grids which were symmetrical along a diagonal axis. I&#xA;also noticed that, of the single-colorings of optimal size which I could&#xA;generate, all with an odd number side-length could be made symmetrical along&#xA;&lt;em&gt;both&lt;/em&gt; diagonals (the evens could not):&lt;/p&gt;</description>
    </item>
    <item>
      <title>Lazy Arithmetic in Haskell</title>
      <link>https://brandon.si/code/lazy-arithmetic-in-haskell/</link>
      <pubDate>Wed, 24 Mar 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/lazy-arithmetic-in-haskell/</guid>
      <description>&lt;p&gt;We don&amp;rsquo;t usually give much thought to Numeric data types beyond whether we&#xA;want to work with integers or decimal numbers. And that is a shame! In this&#xA;post I&amp;rsquo;ll look at how we can actually do arithmetic operations lazily, and in&#xA;the process hopefully reveal a bit about haskell&amp;rsquo;s numeric classes.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;module LazyArithmetic&#xA;    where&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;We will be using&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/numbers-2009.8.9&#34;&gt;Lennart Augustsson&amp;rsquo;s &lt;code&gt;numbers&lt;/code&gt; library&lt;/a&gt; which can be&#xA;installed from hackage with&#xA;&lt;a href=&#34;http://hackage.haskell.org/trac/hackage/wiki/CabalInstall&#34;&gt;cabal-install&lt;/a&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: More about symmetry and a new rotation</title>
      <link>https://brandon.si/code/17x17-more-about-symmetry-and-a-new-rotation/</link>
      <pubDate>Thu, 18 Mar 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-more-about-symmetry-and-a-new-rotation/</guid>
      <description>&lt;p&gt;This is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the &amp;quot;&#xA;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;quot;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;In my &lt;a href=&#34;https://brandon.si/code/17x17-symmetric-single-colorings-and-some-graph-theory/&#34;&gt;last post&lt;/a&gt;,&#xA;I gave a symmetrical rotation of the known 74-cell single-coloring. I want to&#xA;use a slight variation of that grid to show why I think treating the grids as&#xA;symmetrical will help us in solving this problem.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Symmetric Single-Colorings and some Graph Theory</title>
      <link>https://brandon.si/code/17x17-symmetric-single-colorings-and-some-graph-theory/</link>
      <pubDate>Sun, 14 Mar 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-symmetric-single-colorings-and-some-graph-theory/</guid>
      <description>&lt;p&gt;This is part of a&#xA;&lt;a href=&#34;https://brandon.si/tags/17x17/&#34;&gt;series of posts&lt;/a&gt; is related to the&#xA;&amp;ldquo;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17x17 Challenge&lt;/a&gt;&amp;rdquo;&#xA;posted by Bill Gasarch. The goal is to color&#xA;cells of a 17 by 17 grid, using only four colors, such that no rectangle is&#xA;formed from four cells of the same color.&lt;/p&gt;&#xA;&lt;p&gt;In my &lt;a href=&#34;https://brandon.si/code/17x17-some-thoughts-on-the-problem/&#34;&gt;last post&lt;/a&gt;&#xA;I noticed that all of the smaller optimal single-colorings I&#xA;generated showed diagonal symmetry, meaning that row 1 is the same as column&#xA;1, row 8 is the same as column 8, etc. It&amp;rsquo;s my hypothesis that all complete&#xA;single-colorings are symmetrical in this way.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Some Thoughts on the Problem</title>
      <link>https://brandon.si/code/17x17-some-thoughts-on-the-problem/</link>
      <pubDate>Sun, 07 Mar 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-some-thoughts-on-the-problem/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been puzzling over some of the problems presented by the&#xA;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17 x 17 Challenge&lt;/a&gt;, and wanted to share some of what I&amp;rsquo;ve learned&#xA;and have been wondering about. The problem and ultimate goal is to color a 17&#xA;x 17 grid with four colors such that every cell is colored and no rectangle is&#xA;formed by any four cells of the same color.&lt;/p&gt;&#xA;&lt;h2 id=&#34;single-color-subsets&#34;&gt;Single-Color Subsets&lt;/h2&gt;&#xA;&lt;p&gt;I&amp;rsquo;ve started by trying to find an algorithm to find optimal single-color&#xA;subsets, i.e. a way of coloring a grid with one color such that no rectangle&#xA;is formed by the colored cells, and we have the greatest number of cells&#xA;colored as possible. I started thinking of coloring cells one at a time,&#xA;following a path based on the notion of an &amp;ldquo;extended rectangle&amp;rdquo; where the&#xA;fourth side was longer or shorter than the first, to avoid forming rectangles.&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Deterministic algorithm for single-coloring a grid</title>
      <link>https://brandon.si/code/17x17-deterministic-algorithm-for-single-coloring-a-grid/</link>
      <pubDate>Mon, 01 Mar 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-deterministic-algorithm-for-single-coloring-a-grid/</guid>
      <description>&lt;p&gt;I finally got some time to code up a messy script to test out a few&#xA;variations of an algorithm to generate rectangle-free single colorings of a&#xA;grid, as part of a &lt;del&gt;lazy&lt;/del&gt; humble effort to solve the&#xA;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;17 x 17 challenge&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This post is going to be a bit of a code-dump. The algorithm is essentially:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;color cell,&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;turn to the right,&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;stop on first non-rectangle forming cell,&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&#xA;&lt;p&gt;if the cell is uncolored, color it and turn to the right, else if the cell was already colored and has been entered from this direction already, then skip it, else turn to the right&lt;/p&gt;</description>
    </item>
    <item>
      <title>17x17: Brute Force Algorithm for an Optimal Rectangle-Free Subset</title>
      <link>https://brandon.si/code/17x17-brute-force-algorithm-for-an-optimal-rectangle-free-subset/</link>
      <pubDate>Tue, 23 Feb 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/17x17-brute-force-algorithm-for-an-optimal-rectangle-free-subset/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been making notes when I have time, on the&#xA;&lt;a href=&#34;http://blog.computationalcomplexity.org/2009/11/17x17-challenge-worth-28900-this-is-not.html&#34;&gt;&amp;ldquo;17 x 17 challenge&amp;rdquo;&lt;/a&gt;&#xA;posted a couple months back by Bill Gasarch. I&amp;rsquo;ve been&#xA;sketching out algorithms for the problem and wanted to quickly produce some&#xA;optimal rectangle free subsets to check my work and look at. So the code below&#xA;answers the following question:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Imagine an n x n grid. You can color cells of the grid such that no&#xA;rectangle overlayed on the grid will have all four corners colored. Find a&#xA;grid with the maximum possible colored cells.&lt;/p&gt;</description>
    </item>
    <item>
      <title>An alternative definition for Data.List.groupBy</title>
      <link>https://brandon.si/code/an-alternative-definition-for-datalistgroupby/</link>
      <pubDate>Wed, 10 Feb 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/an-alternative-definition-for-datalistgroupby/</guid>
      <description>&lt;p&gt;The function&#xA;&lt;a href=&#34;http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/Data-List.html#v:groupBy&#34;&gt;&lt;code&gt;groupBy&lt;/code&gt;&lt;/a&gt; from haskell&amp;rsquo;s standard library is defined in terms&#xA;of &lt;code&gt;span&lt;/code&gt;, the effect being that the supplied predicate function is used to&#xA;compare the first element of a group with successive elements.&lt;/p&gt;&#xA;&lt;p&gt;This isn&amp;rsquo;t clear from the docs, and you might try to do this and wonder at the&#xA;output you got:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;*Main&amp;gt; groupBy (&amp;lt; =) [3,4,5,3,2,1,4,4,1,1,2,3,4,5,4,5,6,7]&#xA;[[3,4,5,3],[2],[1,4,4,1,1,2,3,4,5,4,5,6,7]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;We can redefine &lt;code&gt;groupBy&lt;/code&gt; as follows, so that the supplied predicate function&#xA;compares adjacent elements one-by-one and returns &lt;code&gt;True&lt;/code&gt; if they should be&#xA;grouped together:&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Definition of Data.List.group</title>
      <link>https://brandon.si/code/the-definition-of-datalistgroup/</link>
      <pubDate>Sat, 06 Feb 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-definition-of-datalistgroup/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve been thinking quite a bit lately about a category of functions that are&#xA;always a bit awkward to define: they involve cases where we would like to&#xA;traverse a recursive data structure and do something with the data that we&#xA;have passed over but which is &amp;ldquo;gone now&amp;rdquo;.  There are many examples of&#xA;functions like these in the haskell standard libraries:&#xA;&lt;code&gt;[span](http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/src/GHC-List.html#span)&lt;/code&gt;,&#xA;&lt;code&gt;[splitAt](http://haskell.org/ghc/docs/latest/html/libraries/base-4.2.0.0/src/GHC-List.html#splitAt)&lt;/code&gt;, etc.&lt;/p&gt;&#xA;&lt;p&gt;A function like &lt;code&gt;group&lt;/code&gt; is in this category. It&amp;rsquo;s conceptually very simple,&#xA;but defining it actually requires a bit of indirection. Here I&amp;rsquo;ve translated&#xA;the definition from &lt;code&gt;Data.List&lt;/code&gt; to use explicit recursion:&lt;/p&gt;</description>
    </item>
    <item>
      <title>A Befunge-93 Interpreter</title>
      <link>https://brandon.si/code/a-befunge-93-interpreter/</link>
      <pubDate>Sun, 31 Jan 2010 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-befunge-93-interpreter/</guid>
      <description>&lt;p&gt;I just finished an initial release of an interpreter for the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Befunge&#34;&gt;befunge&lt;/a&gt; programming language, based on&#xA;the &lt;a href=&#34;http://catseye.tc/projects/befunge93/&#34;&gt;&amp;lsquo;93 spec&lt;/a&gt;. The project was quite&#xA;fun! My goal was to produce a well-designed program with performance that&#xA;didn&amp;rsquo;t suck too bad. Here are some highlights:&lt;/p&gt;&#xA;&lt;h2 id=&#34;design&#34;&gt;Design&lt;/h2&gt;&#xA;&lt;p&gt;I found that writing the core functionality of the interpreter took almost no&#xA;time, once I settled on the approach I would take. I used a monad transformer&#xA;for the first time, &lt;code&gt;StateT&lt;/code&gt;:&lt;/p&gt;</description>
    </item>
    <item>
      <title>DeBruijn Sequences pt.3 - The &#34;Prefer Opposite&#34; algorithm</title>
      <link>https://brandon.si/code/debruijn-sequences-pt3-the-prefer-opposite-algorithm/</link>
      <pubDate>Wed, 02 Dec 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/debruijn-sequences-pt3-the-prefer-opposite-algorithm/</guid>
      <description>&lt;p&gt;This is the third post of mine on DeBruijn sequences, and is in preparation&#xA;for another post to come which I hope should be an interesting investigation&#xA;into a possible parallel algorithm. The first two posts are&#xA;&lt;a href=&#34;https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-1/&#34;&gt;here&lt;/a&gt; and&#xA;&lt;a href=&#34;https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-2/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;This algorithm works identically to the Prefer One algorithm, however&#xA;rather than choose a 1-bit if possible, we instead choose the opposite&#xA;bit from the previous bit, if possible.&lt;/p&gt;&#xA;&lt;p&gt;This has the effect of evening out the locations of the zeros and ones&#xA;throughout the sequence. We will exploit this in a later post where I&#xA;will explore a possible parallel algorithm, which should be interesting&#xA;I hope!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Find a permutation given its Inversion Table</title>
      <link>https://brandon.si/code/find-a-permutation-given-its-inversion-table/</link>
      <pubDate>Sun, 15 Nov 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/find-a-permutation-given-its-inversion-table/</guid>
      <description>&lt;p&gt;Here is some code I whipped up in response to an&#xA;&lt;a href=&#34;http://www.reddit.com/r/coding/comments/a3ckw/programming_problem_find_a_permutation_given_its/&#34;&gt;interesting problem posted on reddit.com/r/coding/&lt;/a&gt;. It was a really interesting&#xA;algorithm to work out:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; Data.List (&lt;span style=&#34;color:#a6e22e&#34;&gt;sortBy&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- takes an inversion list and converts it to the list of permuted  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- elements:  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;decode&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; dec &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; sortBy lowHi &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; zip [&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;..&lt;/span&gt;] &lt;span style=&#34;color:#66d9ef&#34;&gt;where&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    dec as &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; as&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    dec as ((a,&lt;span style=&#34;color:#66d9ef&#34;&gt;_&lt;/span&gt;)&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;is) &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;let&lt;/span&gt; is&amp;#39; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sortBy lowHi (decrementGT a is)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                         &lt;span style=&#34;color:#66d9ef&#34;&gt;in&lt;/span&gt; dec (a&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;as) is&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- decrement every inversion number by 1, for every tuple in which  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- the element is greater than `a`:  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;decrementGT&lt;/span&gt; a &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; map (&lt;span style=&#34;color:#a6e22e&#34;&gt;\&lt;/span&gt;(a&amp;#39;,i) &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; (a&amp;#39;, &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; a&amp;#39;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;a &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; i&lt;span style=&#34;color:#f92672&#34;&gt;-&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; i) )&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- we sort by the inversion number, low to high. For elements with  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- the same inversion number, we say that the greater element tuple  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;-- should go before a lesser element:  &lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;lowHi&lt;/span&gt; (a,i) (a&amp;#39;,i&amp;#39;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; i &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; i&amp;#39; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; a&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;a&amp;#39; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;LT&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;GT&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; otherwise &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; compare i i&amp;#39;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;It&amp;rsquo;s not the prettiest code I&amp;rsquo;ve written, but it&amp;rsquo;s pretty straight-forward and&#xA;concise. Thanks for looking!&lt;/p&gt;</description>
    </item>
    <item>
      <title>An &#34;Adaptive&#34; Move-to-Front Algorithm</title>
      <link>https://brandon.si/code/an-adaptive-move-to-front-algorithm/</link>
      <pubDate>Fri, 13 Nov 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/an-adaptive-move-to-front-algorithm/</guid>
      <description>&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; Thanks to &lt;a href=&#34;http://smj.posterous.com/&#34;&gt;steve&lt;/a&gt; for pointing out that the scheme I describe here is essentially the same as &lt;a href=&#34;http://www.ics.uci.edu/~dan/pubs/DC-Sec5.html#Sec_5.2&#34;&gt;Algorithm BSTW&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I came up with this variation of the&#xA;&lt;a href=&#34;https://brandon.si/code/the-move-to-front-mtf-transform/&#34;&gt;Move-to-Front transform&lt;/a&gt;&#xA;which doesn&amp;rsquo;t require that there be a known alphabet of symbols.&#xA;Instead it builds up the alphabet as it goes along and encounters a new&#xA;symbol. I&amp;rsquo;m sure that this is a known algorithm, as it&amp;rsquo;s a fairly obvious&#xA;variation, but I don&amp;rsquo;t know what the proper name for it is, so I&amp;rsquo;m calling it&#xA;an &lt;a href=&#34;http://www.cs.sfu.ca/CC/365/li/squeeze/AdaptiveHuff.html&#34;&gt;Adaptive&lt;/a&gt; Move-&#xA;to-Front.&lt;/p&gt;</description>
    </item>
    <item>
      <title>The move-to-front (MTF) Transform</title>
      <link>https://brandon.si/code/the-move-to-front-mtf-transform/</link>
      <pubDate>Tue, 10 Nov 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-move-to-front-mtf-transform/</guid>
      <description>&lt;p&gt;To follow up my last &lt;a href=&#34;https://brandon.si/code/polishing-a-functional-pearl-the-burrows-wheeler-transform/&#34;&gt;post about the Burrows-Wheeler Transform&lt;/a&gt;,&#xA;I decided to implement another simple&#xA;algorithm which is often used after the BWT to help consolidate localized&#xA;redundancy in the data before entropy encoding.&lt;/p&gt;&#xA;&lt;p&gt;The idea behind the &lt;a href=&#34;http://www.data-compression.info/Algorithms/MTF/index.htm&#34;&gt;Move-to-Front algorithm&lt;/a&gt; is that we start with some known&#xA;alphabet (like the list of ASCII characters), and encode our data elements as&#xA;the &lt;em&gt;index into that alphabet list&lt;/em&gt; of each element. The trick is that after&#xA;each character is encoded, the alphabet list is modified by &lt;strong&gt;moving&lt;/strong&gt; the&#xA;element whose index we just looked up &lt;strong&gt;to the front&lt;/strong&gt; of the alphabet.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Polishing a Functional Pearl: The Burrows-Wheeler Transform</title>
      <link>https://brandon.si/code/polishing-a-functional-pearl-the-burrows-wheeler-transform/</link>
      <pubDate>Sat, 07 Nov 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/polishing-a-functional-pearl-the-burrows-wheeler-transform/</guid>
      <description>&lt;p&gt;Here is a quick post to get me back into the swing of blogging.&lt;/p&gt;&#xA;&lt;p&gt;I was looking through an old post on StackOverflow about&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Research_papers/Functional_pearls&#34;&gt;clever functional code&lt;/a&gt;,&#xA;and the best answer, given by&#xA;&lt;a href=&#34;http://stackoverflow.com/questions/1524750/what-is-your-favourite-cleverly-written-functional-code/1527026#1527026&#34;&gt;&amp;ldquo;yairchu&amp;rdquo;&lt;/a&gt; was a nice version of the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Burrows%E2%80%93Wheeler%5Ftransform&#34;&gt;Burrows-Wheeler Transform&lt;/a&gt;,&#xA;which is an algorithm for permuting a string such that it can be compressed&#xA;more effectively by other algorithms. The code posted was (import Data.List&#xA;assumed):&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;bwp&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; (&lt;span style=&#34;color:#66d9ef&#34;&gt;Ord&lt;/span&gt; a)&lt;span style=&#34;color:#f92672&#34;&gt;=&amp;gt;&lt;/span&gt; [a] &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; [a]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;bwp&lt;/span&gt; xs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; map snd &lt;span style=&#34;color:#f92672&#34;&gt;$&lt;/span&gt; sort &lt;span style=&#34;color:#f92672&#34;&gt;$&lt;/span&gt; zip (rots xs) (rrot xs)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;rots&lt;/span&gt; xs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; take (length xs) (iterate lrot xs)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;lrot&lt;/span&gt; xs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; tail xs &lt;span style=&#34;color:#f92672&#34;&gt;++&lt;/span&gt; [head xs]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;rrot&lt;/span&gt; xs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; last xs &lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt; init xs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I saw I could improve/shorten this in a couple of obvious ways and came up&#xA;with this:&lt;/p&gt;</description>
    </item>
    <item>
      <title>The State Monad: a tutorial for the confused?</title>
      <link>https://brandon.si/code/the-state-monad-a-tutorial-for-the-confused/</link>
      <pubDate>Sat, 24 Oct 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-state-monad-a-tutorial-for-the-confused/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve written this &lt;del&gt;brief&lt;/del&gt; tutorial on haskell&amp;rsquo;s &lt;code&gt;State&lt;/code&gt; monad to&#xA;help bridge some of the elusive gaps that I encountered in other explanations&#xA;I&amp;rsquo;ve read, and to try to cut through all the sticky abstraction. This is&#xA;written for someone who has a good understanding of the &lt;code&gt;Maybe&lt;/code&gt; and &lt;code&gt;List&lt;/code&gt;&#xA;monads, but has gotten stuck trying to understand State. I hope it&amp;rsquo;s helpful!&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-data-declaration&#34;&gt;The Data Declaration:&lt;/h2&gt;&#xA;&lt;p&gt;To understand a monad you look at its datatype and then at the definition for&#xA;bind (&lt;code&gt;&amp;gt;&amp;gt;=&lt;/code&gt;). Most monad tutorials start by showing you the data declaration&#xA;of a &lt;code&gt;State s a&lt;/code&gt; in passing, as if it needed no explanation:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Cracking a Lock in Haskell with the De Bruijn sequence, pt. 2</title>
      <link>https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-2/</link>
      <pubDate>Tue, 29 Sep 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-2/</guid>
      <description>&lt;p&gt;For this post I will rework the&#xA;&lt;a href=&#34;https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-1/&#34;&gt;Prefer One algorithm from the previous post&lt;/a&gt;&#xA;so that it is much more efficient. We will add&#xA;words to a &lt;a href=&#34;http://en.wikipedia.org/wiki/Patricia_tree&#34;&gt;Patricia Tree&lt;/a&gt;-like&#xA;dictionary as we see them, passing the tree along in the State monad; to check&#xA;if a new word has been seen we simply check in the tree, rather than in the&#xA;array.&lt;/p&gt;&#xA;&lt;p&gt;First, a little boilerplate&amp;hellip;&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-lhs&#34; data-lang=&#34;lhs&#34;&gt;&amp;gt; module Main&#xA;&amp;gt; where&#xA;&amp;gt;&#xA;&amp;gt; import Data.Array&#xA;&amp;gt; import Data.List(isInfixOf, tails)&#xA;&amp;gt;&#xA;&amp;gt; import Control.Monad.State&#xA;&amp;gt; import Control.Arrow&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;new-implementation&#34;&gt;NEW IMPLEMENTATION:&lt;/h3&gt;&#xA;&lt;p&gt;In the previous implementation, to check if the word formed by adding a one&#xA;has been seen, we had to iterate through each of the previous bits in the&#xA;array, checking words.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Cracking a Lock in Haskell with the De Bruijn sequence, pt. 1</title>
      <link>https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-1/</link>
      <pubDate>Thu, 24 Sep 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-1/</guid>
      <description>&lt;p&gt;date = &amp;ldquo;a&amp;rdquo;&#xA;slug = &amp;ldquo;a/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-1&amp;rdquo;&#xA;&lt;a href=&#34;https://brandon.si/code/cracking-a-lock-in-haskell-with-the-de-bruijn-sequence-pt-2/&#34;&gt;Part 2&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A &lt;a href=&#34;http://en.wikipedia.org/wiki/De_Bruijn_sequence&#34;&gt;De Bruijn sequence&lt;/a&gt; is&#xA;(for example) a cyclical list of characters such that every word of a given&#xA;length appears once and only once in the sequence. Instead of using letters,&#xA;you can have a De Bruijn sequence of bits. For example here is one possibility&#xA;for a sequence in which every 3-bit word appears somewhere (you have to wrap&#xA;around from the end for the final &amp;ldquo;words&amp;rdquo;):&lt;/p&gt;</description>
    </item>
    <item>
      <title>Proposed modification to &#39;array&#39; function in Data.Array</title>
      <link>https://brandon.si/code/proposed-modification-to-array-function-in-dataarray/</link>
      <pubDate>Tue, 22 Sep 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/proposed-modification-to-array-function-in-dataarray/</guid>
      <description>&lt;p&gt;In Data.Array the function &lt;code&gt;array :: (IArray a e, Ix i) =&amp;gt; (i, i) -&amp;gt; [(i, e)] -&amp;gt; a i e&lt;/code&gt; takes the array bounds and an association list, and it produces an&#xA;&lt;code&gt;Array&lt;/code&gt;. The function allows you to build an Array by providing the elements&#xA;in whatever order you choose, rather than from the first index to the last.&lt;/p&gt;&#xA;&lt;p&gt;The function &lt;code&gt;listArray&lt;/code&gt; is similar except that it assumes that the list is&#xA;already ordered by index so there is no need to provide tuples of (index,&#xA;value). Becase &lt;code&gt;listArray&lt;/code&gt; actually uses &lt;code&gt;zip&lt;/code&gt; internally to produce the&#xA;tupled list, so the programmer can pass a list to &lt;code&gt;listArray&lt;/code&gt; which &lt;em&gt;exceeds&#xA;the declared bounds of the array&lt;/em&gt; and the function will quietly drop the extra&#xA;list tail:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Some Haskell Boilerplate For Google CodeJam</title>
      <link>https://brandon.si/code/haskell-boilerplate-for-google-codejam/</link>
      <pubDate>Sat, 22 Aug 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/haskell-boilerplate-for-google-codejam/</guid>
      <description>&lt;p&gt;I put together a skeleton module which should be usable for any of the&#xA;problems in this year&amp;rsquo;s&#xA;&lt;a href=&#34;http://code.google.com/codejam/&#34;&gt;Google CodeJam Programming Contest&lt;/a&gt; (as long as they don&amp;rsquo;t adopt a new&#xA;format/pattern for the problems this year). The module includes some useful&#xA;parsing functions which should in the worst case be useful as a cheatsheet for&#xA;those not too experienced with&#xA;&lt;a href=&#34;http://legacy.cs.uu.nl/daan/download/parsec/parsec.html&#34;&gt;Parsec&lt;/a&gt; (*cough me).&#xA;I hope it will encourage people to&#xA;&lt;a href=&#34;http://code.google.com/codejam/contest/registration&#34;&gt;sign up&lt;/a&gt; and use Haskell in&#xA;the contest!&lt;/p&gt;</description>
    </item>
    <item>
      <title>List Grouping module released</title>
      <link>https://brandon.si/code/list-grouping-module-released/</link>
      <pubDate>Fri, 14 Aug 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/list-grouping-module-released/</guid>
      <description>&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; Don&amp;rsquo;t use this package, but use instead&#xA;&lt;a href=&#34;http://hackage.haskell.org/packages/archive/split/0.1.1/doc/html/Data-List-Split.html&#34;&gt;Data.List.Split&lt;/a&gt; by Brent Yorgey. I didn&amp;rsquo;t see that a package like his existed! This module will hopefully be removed from hackage if they can do that.&lt;/p&gt;&#xA;&lt;p&gt;I just finished the initial release of a simple module called&#xA;&lt;a href=&#34;http://hackage.haskell.org/package/list-grouping&#34;&gt;list-grouping&lt;/a&gt; that contains&#xA;functions to partition a list into sub-lists in various ways, based on some&#xA;predicate or integer offset. Functions like these are a little awkward to&#xA;write and I was surprised when I didn&amp;rsquo;t see anything on hackage!&lt;/p&gt;</description>
    </item>
    <item>
      <title>Enumerating all n-integer Sets Which Sum to an Integer x</title>
      <link>https://brandon.si/code/enumerating-all-n-integer-sets-which-sum-to-an-integer-x/</link>
      <pubDate>Thu, 30 Jul 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/enumerating-all-n-integer-sets-which-sum-to-an-integer-x/</guid>
      <description>&lt;p&gt;I came up with what I think is an elegant use of monadic code, while working&#xA;on a program to compute solutions to the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Postage_stamp_problem&#34;&gt;Postage Stamp Problem&lt;/a&gt;.&#xA;The problem asks:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Consider that an envelope is able to hold a limited number of postage&#xA;stamps. Then, consider the set of the values of the stamps &amp;ndash; positive&#xA;integers only. Then, what is the smallest total postage which &lt;em&gt;cannot&lt;/em&gt; be put&#xA;onto the envelope?&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fun with Lazy Arrays: the LZ77 Algorithm</title>
      <link>https://brandon.si/code/fun-with-lazy-arrays-the-lz77-algorithm/</link>
      <pubDate>Thu, 18 Jun 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/fun-with-lazy-arrays-the-lz77-algorithm/</guid>
      <description>&lt;p&gt;This is my third post investigating compression techniques related to the&#xA;DEFLATE algorithm: the first on&#xA;&lt;a href=&#34;https://brandon.si/code/run-length-encoding/&#34;&gt;run-length encoding&lt;/a&gt;, and&#xA;the second on simple&#xA;&lt;a href=&#34;https://brandon.si/code/huffman-coding/&#34;&gt;Huffman Coding&lt;/a&gt;.&#xA;This post models the&#xA;&lt;a href=&#34;http://www.zlib.net/feldspar.html&#34;&gt;LZ77 algorithm, the second of the two compression strategies used by DEFLATE&lt;/a&gt;,&#xA;and in the process explores some interesting properties of Haskell&amp;rsquo;s basic&#xA;Arrays.&lt;/p&gt;&#xA;&lt;h3 id=&#34;implementation&#34;&gt;Implementation:&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-lhs&#34; data-lang=&#34;lhs&#34;&gt;&amp;gt; module LZ77&#xA;&amp;gt;     where&#xA;  &#xA;we will use GHC&amp;#39;s &amp;#34;basic non-strict arrays&amp;#34; for this&#xA;experiment:&#xA;  &#xA;&amp;gt; import Data.Array&#xA;&#xA;and use Ints to store the length of the entire decoded&#xA;message (needed to create our array):&#xA;  &#xA;&amp;gt; type Length = Int&#xA;&amp;gt; type Offset = Int&#xA;  &#xA;in place of the length in the standard length-offset pair&#xA;I&amp;#39;ve decided to use an Int representing the index of the&#xA;last element in the span relative to the element at&#xA;offset. Thus the pair encoding a span of only one element,&#xA;two elements back would be (0,2), rather than the more&#xA;traditional (1,2).&#xA;&#xA;This simply makes more sense to me, especially since I want&#xA;to be able to encoded reversed sequences, as you will see.&#xA;&#xA;&amp;gt; type Index = Int&#xA;  &#xA;and a few simple dataypes for our uncompressed and&#xA;compressed data respectively:&#xA;  &#xA;&amp;gt; type Decoded a = Array Index a&#xA;&amp;gt;&#xA;&amp;gt; data Encoded a = Enc Length [ Either a (Index,Offset) ]&#xA;  &#xA;The decompress function works by traversing the encoded message,&#xA;keeping track of our array index position (since offsets are&#xA;relative to the current position), and building an Array lazily&#xA;from a list which we generate, in part by referencing elements&#xA;from the partially generated array itself.&#xA;  &#xA;So when we see a Right value we look up in the Array the elements&#xA;referenced by the length-offset, concat-ing that list with the&#xA;result of processing the rest of the encoded message.&#xA;  &#xA;If we hit [] in &amp;#39;dec&amp;#39; we call an error because the stored value&#xA;for the length of the uncompressed message in the Encoded type&#xA;was longer than what the &amp;#39;decompress&amp;#39; function could produce.&#xA;&#xA;It&amp;#39;s diffficult to describe, but I hope the code is clear:&#xA;  &#xA;&amp;gt; decompress :: Encoded a -&amp;gt; Decoded a&#xA;&amp;gt; decompress (Enc el es) = decoded&#xA;&amp;gt;     where decoded = listArray (0,el - 1) $ dec 0 es&#xA;&amp;gt;             dec _ [] = error &amp;#34;message is shorter than it should be&amp;#34;&#xA;&amp;gt;             dec n (Left x : xs) = x : dec (n+1) xs&#xA;&amp;gt;             dec n (Right (iRel,off) : xs) =&#xA;&amp;gt;                 let i1 = n - off&#xA;&amp;gt;                     i2 = (if iN &amp;gt; i1 then succ else pred) i1&#xA;&amp;gt;                     iN = i1 + iRel&#xA;&amp;gt;                  in [ decoded!i | i &amp;lt;- [i1, i2 .. iN] ] ++ dec (n + 1 + abs iRel) xs&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Some interesting things about the code above:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Huffman Coding</title>
      <link>https://brandon.si/code/huffman-coding/</link>
      <pubDate>Sun, 31 May 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/huffman-coding/</guid>
      <description>&lt;p&gt;This is the second of probably three posts (the first was on&#xA;&lt;a href=&#34;https://brandon.si/code/run-length-encoding/&#34;&gt;run-length encoding in Haskell&lt;/a&gt;)&#xA;inspired by Thomas Guest&amp;rsquo;s interesting&#xA;&lt;a href=&#34;http://wordaligned.org/articles/deflate-runlength-encoding-but-better&#34;&gt;article on the Deflate algorithm&lt;/a&gt;.&#xA;This is also my first post in literate haskell. Please post any&#xA;improvements to the code if you have them!&#xA;For a refreshingly readable introduction to&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Huffman_coding&#34;&gt;Huffman Coding&lt;/a&gt;&#xA;and the Deflate algorithm,&#xA;&lt;a href=&#34;http://www.zlib.net/feldspar.html&#34;&gt;have a look at this short explanation by Antaeus Feldspar&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;First some boilerplate&amp;hellip;&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-lhs&#34; data-lang=&#34;lhs&#34;&gt;&amp;gt; module Huffman&#xA;&amp;gt;     where&#xA;&#xA;&amp;gt; import Data.List (sort, insert)&#xA;&amp;gt; import qualified Data.Map as M&#xA;&amp;gt; import Data.Function (on)&#xA;&amp;gt; import Control.Arrow (second)&#xA;&#xA;We make an abstract datatype for binary digits. I wonder if this would&#xA;be a nice (but slow?) way of working with binary IO. There doesn&amp;#39;t seem&#xA;to be a package on Hackage for this&#xA;&#xA;  &#xA;&amp;gt; data Bit = O | I&#xA;&amp;gt;          deriving (Show, Ord, Eq)&#xA;&#xA;we define a simple binary tree useful for decoding the encoded binary&#xA;stream. the simple algorithm for assigning codes to our symbols&#xA;produces this tree. A completed tree for some text containing only&#xA;three letter might look like this:&#xA;&#xA;&#xA;         0    /\   1&#xA;             /\ A&#xA;            C B&#xA;&#xA;  &#xA;&amp;gt; data HTree a = Branch {zer :: (HTree a), &#xA;&amp;gt;                        one :: (HTree a),&#xA;&amp;gt;                        wt :: Int }&#xA;&amp;gt;              | Leaf {symb :: a, wt :: Int }&#xA;&amp;gt;              deriving (Show)&#xA;&#xA;&#xA;maps from &amp;lt;Symbol&amp;gt; to &amp;lt;Binary Code&amp;gt;, we create this from the HTree&#xA;built from the list of weighted symbols. the HTree can&amp;#39;t be used for&#xA;encoding.&#xA;  &#xA;&amp;gt; type CodeDict a = M.Map a [Bit]&#xA; &#xA;&#xA;Now some instance declarations so that we know how to order (by weight):&#xA;  &#xA;&amp;gt; instance Ord (HTree a) where&#xA;&amp;gt;     compare = compare `on` wt&#xA;&amp;gt;&#xA;&amp;gt; instance Eq (HTree a) where&#xA;&amp;gt;     (==) = (==) `on` wt&#xA;&#xA;our function for merging two branches which we use to build the HTree&#xA;from the list of symbols and their corresponding weights. no point in&#xA;defining a Monoid instance, but we&amp;#39;ll tip our hat to it:&#xA;  &#xA;&amp;gt; mappend t1 t2 = Branch t1 t2 (wt t1 + wt t2)&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;building-the-coding-trees&#34;&gt;Building the Coding Trees&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-lhs&#34; data-lang=&#34;lhs&#34;&gt;We assign codes to our weighted symbols using a simple algorithm&#xA;which takes the trees (initially Leaves) with the lowest weights&#xA;and combines them (and their weights) and inserts them back into&#xA;the list until they have been combined into a single tree:&#xA;&#xA;  &#xA;&amp;gt; buildDecTree :: [(a,Int)] -&amp;gt; HTree a&#xA;&amp;gt; buildDecTree = build . sort . map (uncurry Leaf)&#xA;&amp;gt;     where build (t:[]) = t&#xA;&amp;gt;           build (t1:t2:ts) = build $ insert (t1 `mappend` t2) ts&#xA;  &#xA;  &#xA;now convert the binary tree representation to a dictionary form for&#xA;encoding. we decompose the tree into a list from the top down, mapping&#xA;either a 1 or 0 over the flattened children. a little confusing:&#xA;  &#xA;&amp;gt; buildEncDict :: (Ord a) =&amp;gt; HTree a -&amp;gt; CodeDict a&#xA;&amp;gt; buildEncDict = M.fromList . build&#xA;&amp;gt;     where build (Leaf t _) = (t,[]) : []&#xA;&amp;gt;           build (Branch a b _) = mapBit O a ++ mapBit I b&#xA;&amp;gt;           -- build up the codes in the snd of each Leaf&amp;#39;s tuple:&#xA;&amp;gt;           mapBit b = map (second (b:)) . build&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;endecoding-functions&#34;&gt;(En/De)coding Functions&lt;/h3&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-lhs&#34; data-lang=&#34;lhs&#34;&gt;To encode a list of symbols for which we&amp;#39;ve generated an HTree, we just&#xA;map over it, looking up it&amp;#39;s code in our Map dictionary:&#xA;  &#xA;&amp;gt; encode :: (Ord a) =&amp;gt; CodeDict a -&amp;gt; [a] -&amp;gt; [Bit]&#xA;&amp;gt; encode d = concatMap (d M.!)&#xA;  &#xA;  &#xA;To decode we simply read a Bit at a time from the input, at the same time&#xA;traversing the HTree (going left when we encounter a zero, and vice versa).&#xA;When we hit a Leaf (the end of a code) we return the symbol and go onto&#xA;the next bit from the top of the HTree once again.&#xA;  &#xA;&amp;gt; decode :: HTree a -&amp;gt; [Bit] -&amp;gt; [a]&#xA;&amp;gt; decode t [] = []&#xA;&amp;gt; decode t bs = dec bs t&#xA;&amp;gt;     where dec bs&amp;#39; (Leaf x _) = x : decode t bs&amp;#39;&#xA;&amp;gt;           dec (O:bs&amp;#39;) (Branch l _ _) = dec bs&amp;#39; l&#xA;&amp;gt;           dec (I:bs&amp;#39;) (Branch _ r _) = dec bs&amp;#39; r&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;usage-examples&#34;&gt;Usage Examples&lt;/h3&gt;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: I scrapped and re-did this section. Should be a little better now.:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Run-length Encoding</title>
      <link>https://brandon.si/code/run-length-encoding/</link>
      <pubDate>Tue, 26 May 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/run-length-encoding/</guid>
      <description>&lt;p&gt;Just a quick implementation of a&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Run-length_encoding&#34;&gt; RLE algorithm&lt;/a&gt; for lists in haskell. We compress a list by converting&#xA;&amp;ldquo;runs&amp;rdquo; of consecutive elements into a tuple of the form: (run length,&#xA;element).&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; Data.List (&lt;span style=&#34;color:#a6e22e&#34;&gt;group&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; Control.Arrow&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;runLengthEnc&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Eq&lt;/span&gt; a &lt;span style=&#34;color:#f92672&#34;&gt;=&amp;gt;&lt;/span&gt; [a] &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; [(&lt;span style=&#34;color:#66d9ef&#34;&gt;Int&lt;/span&gt;,a)]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;runLengthEnc&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; map (length &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&amp;amp;&lt;/span&gt; head) &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; group&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;decode&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; [(&lt;span style=&#34;color:#66d9ef&#34;&gt;Int&lt;/span&gt;, a)] &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; [a]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;decode&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; concatMap (uncurry replicate)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the &lt;code&gt;&amp;amp;&amp;amp;&amp;amp;&lt;/code&gt; combinator looks foreign to you, check out David R. Maciver&amp;rsquo;s&#xA;&lt;a href=&#34;http://www.drmaciver.com/2007/08/playing-with-arrows/&#34;&gt;very enlightening blog about Arrow functions&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Partial Application and a simple Mastermind game</title>
      <link>https://brandon.si/code/partial-application-and-a-simple-mastermind-game/</link>
      <pubDate>Sun, 17 May 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/partial-application-and-a-simple-mastermind-game/</guid>
      <description>&lt;p&gt;I thought this was a good, simple example of how&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Currying&#34;&gt;currying and partial application&lt;/a&gt; can be used in a&#xA;very expressive way. We create a one-liner to play the game&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Mastermind_%28board_game%29&#34;&gt;mastermind&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In the type signature we include unnecessary parentheses, to be clear that we&#xA;are thinking of the function not as &lt;em&gt;&amp;ldquo;a function taking a secret code and a&#xA;guess and returning a score for the guess&amp;rdquo;&lt;/em&gt; but as &lt;em&gt;&amp;ldquo;a function taking a&#xA;secret code and returning a scoring function for that code&amp;rdquo;&lt;/em&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Gnome Sort</title>
      <link>https://brandon.si/code/gnome-sort/</link>
      <pubDate>Mon, 11 May 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/gnome-sort/</guid>
      <description>&lt;p&gt;In my boredom, I implemented the toy sorting algorithm called&#xA;&lt;a href=&#34;http://www.cs.vu.nl/~dick/gnomesort.html&#34;&gt;Gnome Sort&lt;/a&gt;. It accomplishes backtracking&#xA;by using a zipper-like system of two lists treated as stacks, and is about&#xA;100X slower than GHC&amp;rsquo;s merge sort on&#xA;&lt;a href=&#34;http://neilmitchell.blogspot.com/2008/03/sorting-at-speed.html&#34;&gt;the test I used&lt;/a&gt;. It&amp;rsquo;s&#xA;also not especially small or simple-looking. It&amp;rsquo;s basically terrible:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;gnomeSort&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; (&lt;span style=&#34;color:#66d9ef&#34;&gt;Ord&lt;/span&gt; a)&lt;span style=&#34;color:#f92672&#34;&gt;=&amp;gt;&lt;/span&gt; [a] &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; [a]&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;gnomeSort&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sort &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;where&lt;/span&gt; sort rs &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; rs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          sort &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt; (x&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;xs) &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sort [x] xs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          sort (r&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;rs) (x&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;xs)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; x &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; r &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sort rs (x&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;r&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;xs)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;              &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; otherwise &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; sort (x&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;r&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;rs) xs&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The above doesn&amp;rsquo;t keep track of where it left off before it began to&#xA;backtrack, an obvious optimization which turned the algorithm into an&#xA;insertion sort:&lt;/p&gt;</description>
    </item>
    <item>
      <title>directory-tree module released</title>
      <link>https://brandon.si/code/directory-tree-module-released/</link>
      <pubDate>Sat, 09 May 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/directory-tree-module-released/</guid>
      <description>&lt;p&gt;I&amp;rsquo;ve released my first package,&#xA;&lt;a href=&#34;http://hackage.haskell.org/cgi-bin/hackage-scripts/package/directory-tree&#34;&gt;up now on hackage&lt;/a&gt;&#xA;(haddock docs should be&#xA;generated soon). The module provides a simple data structure that mirrors a&#xA;directory tree, and some useful functions for doing IO on directories of&#xA;files. You can&#xA;&lt;a href=&#34;https://brandon.si/code/a-directorytree-module-and-some-examples/&#34;&gt;read more about it here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;It&amp;rsquo;s very likely there are some bugs, especially related to cross platform&#xA;issues with file names and paths. The module is also fairly bare, so please&#xA;send me any requests for functionality that I haven&amp;rsquo;t thought of, as well as&#xA;any bugs you might find.&lt;/p&gt;</description>
    </item>
    <item>
      <title>a DirectoryTree module and some examples</title>
      <link>https://brandon.si/code/a-directorytree-module-and-some-examples/</link>
      <pubDate>Thu, 30 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/a-directorytree-module-and-some-examples/</guid>
      <description>&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;: I&amp;rsquo;ve just released this as my first package on hackage. You can read&#xA;more and write any comments &lt;a href=&#34;https://brandon.si/code/directory-tree-module-released/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I just put together a library that provides a simple tree data structure to&#xA;represent the structure of files and directories in the OS. It provides some&#xA;simple IO functions like &lt;code&gt;readDirectory&lt;/code&gt; (analogous to &lt;code&gt;readFile&lt;/code&gt;) which&#xA;&amp;ldquo;opens&amp;rdquo; a directory, returning a DirTree of Strings in the IO monad.&lt;/p&gt;&#xA;&lt;p&gt;The nice thing is that by defining a simple instance for&#xA;&lt;a href=&#34;http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Traversable.html&#34;&gt;Traversable&lt;/a&gt;&#xA;(and the default instances for Foldable and Functor that we&#xA;get for free) we get a whole array of nice functions which we can apply to&#xA;directory structures! For example, we can combine all the text in a directory&#xA;of files with:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Why I love Hoogle</title>
      <link>https://brandon.si/code/why-i-love-hoogle/</link>
      <pubDate>Sat, 25 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/why-i-love-hoogle/</guid>
      <description>&lt;p&gt;I&amp;rsquo;m working on a module called &lt;code&gt;DirectoryTree&lt;/code&gt;, a simple tree structure&#xA;mirroring the structure of a directory tree in the&#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Input/output&#34;&gt;outside world&lt;/a&gt;, with functions to hopefully&#xA;make it easy to do useful things (I&amp;rsquo;m not sure if something like this already&#xA;exists). Here is the data-type:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;data&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;DirTree&lt;/span&gt; a &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Dir&lt;/span&gt; { name &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;String&lt;/span&gt;,&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       files &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; [a],&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                       directories &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; [&lt;span style=&#34;color:#66d9ef&#34;&gt;DirTree&lt;/span&gt; a] }&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;               &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Fail&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;String&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;--file/directory name&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I would like to do things like map over a &lt;code&gt;DirTree&lt;/code&gt; of &lt;code&gt;FilePath&lt;/code&gt;s, returning&#xA;a tree (in the IO monad) of &lt;code&gt;Handle&lt;/code&gt;s&amp;hellip; so the code involves a lot of&#xA;slogging through the IO monad, which I&amp;rsquo;m not totally comfortable with yet.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Initial tests of Tries: Follow Up</title>
      <link>https://brandon.si/code/initial-tests-of-tries-follow-up/</link>
      <pubDate>Sat, 18 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/initial-tests-of-tries-follow-up/</guid>
      <description>&lt;p&gt;This is to wrap up my&#xA;&lt;a href=&#34;https://brandon.si/code/some-initial-tests-of-tries/&#34;&gt;previous post about Tries&lt;/a&gt;&#xA;and my attempts at an implementation, and to summarize some of the things I&#xA;think I learned about implementing a Trie structure in Haskell.&lt;/p&gt;&#xA;&lt;h3 id=&#34;complexity-is-slow&#34;&gt;Complexity is Slow&lt;/h3&gt;&#xA;&lt;p&gt;My initial idea of using a container type at each node to store the collection&#xA;of branches was a good idea for testing (I could easily swap in Data.Map, or&#xA;my own simple binary tree) and convenience (I could use Data.Map&amp;rsquo;s built-in&#xA;functions to insert the element of the list key into the the container); but&#xA;it turned out to be bad for performance.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Some initial tests of Tries</title>
      <link>https://brandon.si/code/some-initial-tests-of-tries/</link>
      <pubDate>Thu, 16 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/some-initial-tests-of-tries/</guid>
      <description>&lt;p&gt;I have been interested in writing a &lt;a href=&#34;http://en.wikipedia.org/wiki/Trie&#34;&gt;Trie&lt;/a&gt;&#xA;implementation to see how its performance compares to using Data.Map for&#xA;storing dictionary-like data. I wrote a minimal implementation of Tries which&#xA;exports &lt;code&gt;insert&lt;/code&gt;,&lt;code&gt;insertWith&lt;/code&gt;, and &lt;code&gt;lookup&lt;/code&gt; definitions and can be used in&#xA;place of &lt;code&gt;Data.Map&lt;/code&gt; for those functions. I tested the implementation using a&#xA;program &lt;code&gt;frequency.hs&lt;/code&gt; which reads a source file and uses &lt;code&gt;insertWith&lt;/code&gt; on each&#xA;word to count the frequency of the words in a file; we then use &lt;code&gt;lookup&lt;/code&gt; to&#xA;print out the frequencies of a list of arbitrary words.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Cycle Detection</title>
      <link>https://brandon.si/code/cycle-detection/</link>
      <pubDate>Sun, 12 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/cycle-detection/</guid>
      <description>&lt;h3 id=&#34;the-algorithm&#34;&gt;The Algorithm&lt;/h3&gt;&#xA;&lt;p&gt;We can use &lt;a href=&#34;http://en.wikipedia.org/wiki/Cycle_detection#Brent.27s_algorithm&#34;&gt;Brent&amp;rsquo;s Algorithm&lt;/a&gt;&#xA;to detect infinitely-repeating sequences in a list of values generated by some&#xA;iterated function: that is, any list in which the next value in the sequence&#xA;is generated from the previous value alone; if we find duplicate values in the&#xA;list, we know we have a cycle.&lt;/p&gt;&#xA;&lt;p&gt;The implementation below isn&amp;rsquo;t particularly elegant, and since I want to use&#xA;it as a stand-alone tool I&amp;rsquo;m having it output strings:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Parallel List Comprehensions with a Monte Carlo example</title>
      <link>https://brandon.si/code/parallel-list-comprehensions-with-a-monte-carlo-example/</link>
      <pubDate>Wed, 08 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/parallel-list-comprehensions-with-a-monte-carlo-example/</guid>
      <description>&lt;p&gt;GHC has an extension to the list comprehensions syntax that replicates the&#xA;functionality of &lt;code&gt;zipWith&lt;/code&gt;, by allowing you to have two generators running in&#xA;parallel. Turn on the extension in GHCi like so:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Prelude&amp;gt; :set -XParallelListComp&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I use the extension below to generate an infinite list of random coordinates&#xA;(scaled to a  1000x1000 grid) using two different &#xA;&lt;a href=&#34;http://en.wikipedia.org/wiki/Linear_congruential_generator&#34;&gt;Linear Congruential Generators&lt;/a&gt;&#xA;running in parallel. It should be simple to modify the code below to actually run the&#xA;generators concurrently using&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/GHC/Data_Parallel_Haskell&#34;&gt;Data Parallel Haskell&lt;/a&gt;&#xA;(although I haven&amp;rsquo;t had a chance to play with that yet).&lt;/p&gt;</description>
    </item>
    <item>
      <title>The Total Recall combinator</title>
      <link>https://brandon.si/code/the-total-recall-combinator/</link>
      <pubDate>Wed, 01 Apr 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/the-total-recall-combinator/</guid>
      <description>&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;infixr&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;9&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;.:&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#f92672&#34;&gt;.:&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; (b &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; c) &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; (a &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; a1 &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; b) &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; a &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; a1 &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; c&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;(&lt;span style=&#34;color:#f92672&#34;&gt;.:&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; (&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;)(&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;)(&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This can be used to compose a string of functions with a binary function stuck&#xA;on the end. For example:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;lookupPlusOne&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; (&lt;span style=&#34;color:#66d9ef&#34;&gt;Ord&lt;/span&gt; k, &lt;span style=&#34;color:#66d9ef&#34;&gt;Monad&lt;/span&gt; m, &lt;span style=&#34;color:#66d9ef&#34;&gt;Num&lt;/span&gt; n) &lt;span style=&#34;color:#f92672&#34;&gt;=&amp;gt;&lt;/span&gt; k &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Map&lt;/span&gt; k n &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; m n&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;lookupPlusOne&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; liftM (&lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;.:&lt;/span&gt; lookup&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(picked up from some folks on&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/IRC_channel&#34;&gt;#haskell&lt;/a&gt;)&lt;/p&gt;</description>
    </item>
    <item>
      <title>Building a Tree from an Ordered List</title>
      <link>https://brandon.si/code/building-a-tree-from-an-ordered-list/</link>
      <pubDate>Tue, 31 Mar 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/building-a-tree-from-an-ordered-list/</guid>
      <description>&lt;p&gt;A nice recursive algorithm for building a nearly-optimal binary search&#xA;tree from an &lt;strong&gt;ordered list&lt;/strong&gt;.:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;data&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Tree&lt;/span&gt; a &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Node&lt;/span&gt; a (&lt;span style=&#34;color:#66d9ef&#34;&gt;Tree&lt;/span&gt; a) (&lt;span style=&#34;color:#66d9ef&#34;&gt;Tree&lt;/span&gt; a)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;            &lt;span style=&#34;color:#f92672&#34;&gt;|&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;End&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The algorithm &lt;code&gt;divide&lt;/code&gt;s the input list into sublists of increasing length:&#xA;1,2,4,8&amp;hellip; The first element of each sublist is the &amp;ldquo;keystone&amp;rdquo; of a subtree&#xA;assembled with &lt;code&gt;mkTree&lt;/code&gt;. :&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-haskell&#34; data-lang=&#34;haskell&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;fromSorted&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;::&lt;/span&gt; [a] &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Tree&lt;/span&gt; a&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;fromSorted&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; foldl mkTree &lt;span style=&#34;color:#66d9ef&#34;&gt;End&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt; divide &lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;where&lt;/span&gt; mkTree l (n&lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt;ns) &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;Node&lt;/span&gt; n l (fromSorted ns)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          divide &lt;span style=&#34;color:#66d9ef&#34;&gt;_&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;[]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;          divide c xs &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; take c xs &lt;span style=&#34;color:#66d9ef&#34;&gt;:&lt;/span&gt; divide (c&lt;span style=&#34;color:#f92672&#34;&gt;*&lt;/span&gt;&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;) (drop c xs)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Variations that used &lt;code&gt;splitAt&lt;/code&gt; instead of the separate &lt;code&gt;take&lt;/code&gt; and &lt;code&gt;drop&lt;/code&gt; were&#xA;no more efficient (perhaps because of&#xA;&lt;a href=&#34;http://www.haskell.org/haskellwiki/Sharing&#34;&gt;sharing&lt;/a&gt;?) nor was using the&#xA;strict &lt;code&gt;foldl&#39;&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Data.Map Conversion Functionality</title>
      <link>https://brandon.si/code/datamap-functions/</link>
      <pubDate>Sun, 29 Mar 2009 00:00:00 +0000</pubDate>
      <guid>https://brandon.si/code/datamap-functions/</guid>
      <description>&lt;p&gt;There are three identical functions in &lt;code&gt;Data.Map&lt;/code&gt; for flattening a Map to a&#xA;list of tuples in ascending order:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;code&gt;assocs = toList = toAscList&lt;/code&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&amp;hellip;but nothing to convert to a descending list.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
