This is a weblog about computing, culture et cetera, by . Read more.


What are hybrid maps?

A heterogenous collection of birds.

A heterogenous collection of birds.

Clojure people sometimes talk about hybrid maps. What are they talking about?

A map, in general, is a data structure that associates keys with values. There are two common usage patterns for maps in Clojure:

See LispCast for a more extensive discussion of these patterns.

A hybrid map is a map that acts as a record and as an index at the same time. This pattern is not common – usually it’s better to have the index map as a field in the record. One case where it works nicely is the Clojure map destructuring syntax:

(let [{var1 :key1 var2 :key2 :keys [key3] :as result}
      (some-function-call ...)]
  ...)

Here :keys and :as work like record fields, but the bindings for var1 and var2 work like an index.

What about heterogenous maps?

A map is heterogenous if it can contain keys and/or values of multiple types. If a map is not heterogenous, it’s homogenous. Here are some examples:

{:a 1 :b 2}         ; homogenous
{:a 1 :b "hello"}   ; heterogenous values
{:a 1 "b" 2}        ; heterogenous keys
{:a 1 "b" "hello"}  ; heterogenous keys and values
{}                  ; could be either!

This concept is not discussed much in the Clojure community, because Clojure maps are heterogenous by default.1 An example of less-heterogenous map in Clojure is data.int-map, where the keys must be integers. The values can still be anything, though.

The concept of heterogenous maps, and of heterogenous collections in general, is more interesting in statically typed languages like Scala and Haskell. Expressing the type of a homogenous map is straightforward, but typing a heterogenous map is more complex. This is can be seen in how there are separate libraries for heterogenous collections, like the popular shapeless library for Scala.

What’s the relationship between hybrid maps and heterogenous maps? There’s no relationship, really. Like records, hybrid maps often are heterogenous, but there’s no reason for why you couldn’t use a homogenous map for a hybrid purpose.


  1. Unless you argue that Clojure is unityped, in which case all Clojure maps are homogenous.


ZuriHac 2017

The basic dilemma of ZuriHac: to stay inside and code or to enjoy the lake?

The basic dilemma of ZuriHac: to stay inside and code or to enjoy the lake?

ZuriHac, the Haskell hackathon in/near Zürich, took place this weekend and it was again great!

These days hackathon usually means a prototyping competition. ZuriHac is a hackathon in a different sense. There’s no competition. Instead, people come there to collaborate, to learn, and to have fun together. Together we worked on open-source projects, taught each other Haskell, and had good time drinking beer by the lake.

There were some talks, too. The keynotes were given by seasoned Haskellers, but my favorite was the talk given by Mario Meili and Cyrill Schenkel. Mario and Cyrill are students in HSR Hochschule für Technik Rapperswil, where the event took place. They presented their work-in-progress master’s theses.

Mario’s part turned out to be a quite provocative conversation opener. His thesis is about what prevents the wider adoption of Haskell in the industry. He had gathered often-presented concerns about Haskell like its poor performance. The listeners were quick to shoot these claims down, but Mario does have a point – people really do believe these things about Haskell.

My take is that Haskell’s lack of industrial success is not about its drawbacks. The lack of compelling benefits is the actual problem. It’s hard to make a concrete case for Haskell.

Some familiar faces from Helsinki having fun with FunLists.

Some familiar faces from Helsinki having fun with FunLists.

While on the plane back home, I read this article about the rOpenSci’s Unconference. Sean Kross describes the Unconf like this:

Some have described it as a hackathon, but I think that’s a mischaracterization. Though a great deal of code is written in a short period of time, a substantial proportion of the attendees make large and important contributions while hardly writing any code. The Unconf is not a competition, and it’s intensely social and collaborative.

Sounds like Unconf’s spirit is similar to ZuriHac’s spirit! This is a great event format for programming communities – it’s more social and more collaborative than the usual conferences. After all, everybody seems to agree that the social part is the best part of conferences.


Commit messages are worthless

Commit messages written in rush tend to be less than helpful.

Commit messages written in rush tend to be less than helpful.

A couple of years ago I wrote about how I hoped that writing good commit messages is worthwhile. It never paid off.

Turns out it’s never my commit messages I’m reading. It’s my coworkers’ messages, or open-source contributors’ messages. It’s not enough that you write good messages, you need to foster a culture of good commit messages in all the projects you work with.

Even people who write good commit messages most of the time sometimes create commits with messages like “make it work” or “WIP” or “blargh”. For some reason it’s always these commits that contain the mysterious bugs or the unclear code.

Even if you do write good commit messages, if you use GitHub, it’s likely that nobody reads the messages. GitHub’s user interface isn’t designed for reading commit messages. When you do a pull request, the commit titles are in small font and the bodies are hidden. If you use GitHub, it’s better to spend time on writing good pull request messages. They do get read.


For more posts, see archive.