How to Make a Thing in Haskell, Part 1: Motivation

Haskell is, allegedly, one of those languages that bends your mind a lot, but you never write Real Programs in. Well, I’m going to build my first Real Live Program in Haskell. I’ve picked a nontrivial but reasonably-scoped tool I want to build, and I thought I’d write about building it as I go, just to solidify my knowledge of the tools and concepts I need. So, this is the first of a series of posts where I’ll document the process of learning to do a Haskell for real. In this post, I’ll motivate my project, talking about why I’m using Haskell and about the tool I’m cloning. In future posts, I’ll set up cabal to build and test my program, and then actually build and test the thing!

Haskell & Me

I’ve been interested in Haskell for years now – I remember trying to work through Learn You a Haskell as early as 2010. Since then, I’ve spent a little time every 6 months or so re-familiarizing myself with the language and its concepts, more or less starting over each time. I get the sense that I’m in good company, and a lot of people learn Haskell in fits and starts.

And now I’m back at it! I got started again largely thanks to exercism. exercism is a social programming practice site built and run by Katrina Owen. It gives you a CLI you can use to download test suites for programming exercises in over a dozen languages, then upload your solutions to be nitpicked by other users. It’s put my Haskell code in front of lots of smart people like Bob Ippolito. He doesn’t know me from Adam but has generously spent his time using giving me (and many others!) feedback on my solutions and taught me a lot about Haskell and functional programming. I’m grateful for that. It’s improved my Haskell a lot. 1

I also think it’s made me a better programmer by teaching me to design, compose, and use pure functions with no side effects. It’s a good discipline in any language, and it’s enforced by one hell of a type system in Haskell. This enforced separation of concerns helped me think clearly about the Clean Architecture, which has been in my peripheral vision for a while now, and which has recently started to click for me.

The impact Haskell has had on my architectural thinking is what makes me feel that now is the right time for me to take a step up from exercises and build an actual program, one that I have to design architect properly. I’d been wondering what to make for a few weeks when I saw this tweet from Gary Bernhardt:

And that put selecta and Haskell together in my head, and now they’re stuck there. SO:

I’m going to build a selecta clone in Haskell. I’m not the first person to do it, but that’s cool! I’m going to call it skellect. It’s an ugly name, but it’s my ugly name. I’ll use it as an opportunity to learn how Haskell enforces architectural discipline, and to learn its tooling for building and testing programs.

I spent a couple hours the other day getting a proof-of-concept up and running. It’s badly built, and broken in a lot of ways, but now I understand the problems the program has to solve, and I’m confident that I can build an industrial-strength version.

What is selecta?

selecta is an awesome command-line tool written by Gary Bernhardt. It’s an interactive fuzzy finder designed to be used as a filter in shell pipelines. The example in its README shows a simple example of selecta in action:

Gary Bernhardt's `selecta` example

So, the command cat $(ls | selecta)

It’s pretty awesome!

So, what does selecta do as it executes? My understanding of this is based on Gary Bernhardt’s description of its operation and on my Haskell proof-of-concept implementation:

So, this project will involve

Seems like a good set of things to learn to do in Haskell! Dealing with multiple I/O streams will be a good exercise. In particular, dealing with cursor manipulation and rewriting tty will likely be a little more complicated than just reading to and printing from I/O streams, so that’ll be a good thing to learn to do. Should be fun!

  1. If you want to learn a new language or do some kata-style exercises in one you already know, you should totally join exercism and start a team with me!