Haskell

Extracting open library author names using Haskell Conduits

Almost anyone productively using Haskell has already stumbled upon Michael Snoyman’s Conduit library.

In this post I will show how to leverage the power of Conduit interleaved IO in order to parse author’s names from the Open Library data dumps.

Using traditional languages like Java or C, it would be significantly more difficult and error-prone to interleave the processing pipeline actions of

  • Downloading the file ol_dump_authors_latest.txt.gz using HTTP
  • Decompressing using a gunzip-like function
  • Splitting into lines and discarding everything but the JSON from said lines
  • Appropriately decoding the JSON and extracing the name field, or ignoring the line if parsing is not possible
  • Writing all said names into a files (authors.txt in this example), one per line.

Continue reading →

Posted by Uli Köhler in Haskell

Get current hour / minute / second in Haskell

Problem:

Using haskell, you want to get the current hour / minute / second (for the current timezone) as integral values.

Continue reading →

Posted by Uli Köhler in Haskell

Using QuasiQuotation for more readable Atom code

Lately I’ve been experimenting with using Atom to generate intrinsically reliable embedded software.

In contrast to alternatives like Copilot in Atom you include the surrounding C code as Haskell strings whereas other concepts just generate a set of C files to include in your main code.

Continue reading →

Posted by Uli Köhler in Haskell

Get current year / month / day in Haskell

Problem:

Using haskell, you want to get the current year, month and day (for the UTC time zone) as integral values.

Continue reading →

Posted by Uli Köhler in Haskell

Parsing the OUI database in Haskell

In this post, we will show a method and provide a Haskell module capable of parsing both the IEEE OUI list and the IEEE IAB list.

While our code only parses the databases into an object form and doesn’t insert them into a tree capable of fast MAC address -> vendor lookup, it is based on Attoparsec, providing good performance and high flexibility for changes.

Continue reading →

Posted by Uli Köhler in Haskell

Haskell: Invert filter predicate

Problem: In Haskell, you intend to filter with an inverted filter operator.

For example, your code is (GHCi):

Prelude> import Data.List
Prelude Data.List> filter ( isPrefixOf "a" ) ["a","ab","cd","abcd","xyz"]
["a","ab","abcd"]

The list you need is ["cd","yz"]. In some cases, the easiest solution would be to use for example <= instead of >, but there isn’t a literal complement for all functions, like for example isPrefixOf, which is being used in the example.

Continue reading →

Posted by Uli Köhler in Haskell

Haskell: Compress with GZip and write to file

Problem:

In Haskell, you want to gzip-compress a string and write it to a file.

Continue reading →

Posted by Uli Köhler in Haskell