This is an old revision of the document!


Empirical Research: How Monads are used in Haskell

Article submitted to the Science of Computer Programming Journal. This is an extended version of the SBLP 2017 article.

Abstract

Monads are a denotational approach to embed and reason about notions of computation such as mutable state, I/O, exceptions, and many others. Even though monads are technically language-agnostic, they are mostly associated to the Haskell language. Indeed, one could argue that the use of monads is one of the defining characteristic of the Haskell language. In practical terms, monadic programming in Haskell relies on the standard mtl package library, which provides 8 notions of computation: Identity, Error, List, State, Reader, Writer, RWS, and Continuations. Despite their widespread use, we are not aware of any empirical investigations regarding how developers use monads. In this paper we present an empirical study that covers all packages available in a snapshot of the Hackage repository, covering 3245 different packages, 85135 total package-version combinations, and around 5842979 Haskell files. To the best of our knowledge this is the first large-scale analysis of Hackage with regards to monads and their usage. Our results show that around 30.8 modules depend on the mtl package, whereas only 69.2 yet compatible implementations. Nevertheless, usage patterns for each specific monad remain similar both for mtl and alternatives. Regarding usage, the State computation, as well as its variations such as Reader and Writer is by far the most used one. Perhaps surprisingly, the library for monad transformers takes a very close second place. We also report on the distribution of packages that use mtl, regarding their category and stability level.

Datasets and analysis scripts


SBLP 2017 article

Article accepted at the 21st Brazilian Symposium of Programming Languages, in the context of CBSoft 2017. Work presented on September 22th, at the Universidad Federal de Ceará.

Abstract

Monads are a denotational approach to embed and reason about notions of computation such as mutable state, I/O, exceptions, and many others. Even though monads are technically language-agnostic, they are mostly associated to the Haskell language. Indeed, one could argue that the use of monads is one of the defining characteristic of the Haskell language. In practical terms, monadic programming in Haskell relies on the standard mtl package library, which provides 8 notions of computation: identity, error, list, state, reader, writer, RWS, and continuations. Despite their widespread use, we are not aware of any empirical investigations regarding how developers use monads. In this paper we present preliminary results of an empirical study that quantitatively describe how monads are used in a sample of the Hackage repository. Our results show that around 25% of sampled modules depend on the mtl package, whereas only 1% depend on alternative, yet compatible implementations. Nevertheless, usage patterns for each specific monad remain similar both for mtl and alternatives. Regarding usage, the state monad is by far the most used one, although all of them are used. We also report on the distribution of packages that use mtl, regarding their category and stability level.

Datasets and analysis scripts