Haskell interlude

Okay, wordpress sux majorly; it kept messing this up every time I tried to post.

I’ll just have to write a successor to WordPress in Haskell (starting with clckwrks?) … sigh… (if I have time to rewrite every major piece of software in the world…)

I’ll probably post some SQL, PowerShell, or even maybe DAX soon (when I get deeper into DAX). Or at least F#. But here’s some Haskell that shows how concisely a binary-file-decoding task can be concisely-written.

The story: Years ago, I write a sort of Scrabble-cheat program called anagram ( http://my.streetpulse.com/shared/anagram.zip ) . It does a brute-force search of a word list to find all possible anagrams of the given rackletters, including blanks (repeatedly, due to careless coding, and to avoid having to implement a sort, or bucketization, or memory-allocation.) To save RAM, I encoded the word-list enable1.txt with what I called “prefix-compression”, meaning that if you have aardvark first, then aaple next, the encoded file just stores “ple” for the second word, with a byte-sized integer 2 to indicate that two characters can be copied from the previous word. This encoding can be decoded with scanl as-follows:
<pre>I’ll probably post some SQL, PowerShell, or even maybe DAX soon (when I get deeper into DAX). Or at least F#. But here’s some Haskell that shows how concisely a binary-file-decoding task can be concisely-written.

The story: Years ago, I write a sort of Scrabble-cheat program called anagram ( http://my.streetpulse.com/shared/anagram.zip ) . It does a brute-force search of a word list to find all possible anagrams of the given rackletters, including blanks (repeatedly, due to careless coding, and to avoid having to implement a sort, or bucketization, or memory-allocation.) To save RAM, I encoded the word-list enable1.txt with what I called “prefix-compression”, meaning that if you have aardvark first, then aaple next, the encoded file just stores “ple” for the second word, with a byte-sized integer 2 to indicate that two characters can be copied from the previous word. This encoding can be decoded with scanl as-follows:</pre>
<pre>I’ll probably post some SQL, PowerShell, or even maybe DAX soon (when I get deeper into DAX). Or at least F#. But here’s some Haskell that shows how concisely a binary-file-decoding task can be concisely-written.

The story: Years ago, I write a sort of Scrabble-cheat program called anagram ( http://my.streetpulse.com/shared/anagram.zip ) . It does a brute-force search of a word list to find all possible anagrams of the given rackletters, including blanks (repeatedly, due to careless coding, and to avoid having to implement a sort, or bucketization, or memory-allocation.) To save RAM, I encoded the word-list enable1.txt with what I called “prefix-compression”, meaning that if you have aardvark first, then aaple next, the encoded file just stores “ple” for the second word, with a byte-sized integer 2 to indicate that two characters can be copied from the previous word. This encoding can be decoded with scanl as-follows:

I tried <pre> and <blockquote> in html editing mode but couldn’t get this indented code to save properly; WordPress cuts it off every time.  Maybe I’ll post it to github.com/tallpeak … ahh, that’s nice; here it is:

https://gist.github.com/tallpeak/24dabfce6b5bf901d0e31eab0ca30aef

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s