In Clojure We Trust

A piece of intertube about the Clojure programming language, algorithms and Emacs.

Playing With Haskell

After reading a few books on Haskell I had to face the reality: learning by doing a project was necessary!

I chose a project which was easy enough to be finished in a few weeks or months (but still slightly challenging) and had a practical utility.

My project is a JSON command-line utility loosely inspired by underscore-cli and Hawk. Arbitrary Lens expressions can be used to filter or transform the input.

If you don’t know what Lens are, think of them as getters/setters/filters/functions combinators similar to JQuery or CSS selectors but for any type of data-structures. I’m still a beginner regarding Lens.

The challenge for me was to learn how to dynamically evaluate Haskell expressions. This is uncommon since Haskell is statically typed. The library I used to do that is naturally limited in its functionality in comparison to a Lisp but the final result is all but disappointing.

For the purpose of my program I implemented a pretty printer for JSON similar to aeson-pretty but with colors. Maybe I should package it for Hackage?

Once I had hdevtools setup for cabal sandboxes, programming in Haskell was enjoyable. Refactoring is easy thanks to the strong type system. I was stuck once or twice with the type system but the people on the #haskell channel were helpful. The code has a certain form of esthetic even if I feel more knowledge would allow me to be cleaner. For example I wonder if it is possible to avoid pattern matching on Left and Right for multiple calls which return something like IO (Either x y), since both IO and Either are monads.

You can have a look at the project here:

https://github.com/kototama/jp

Comments