31

There are many different monad transformers libraries on Hackage. A few seem to get more attention than the others. To name a few: mtl (current version depending on transformers for some reason), transformers, monadLib, monads-tf, mtlx, contstuff.

Which one should be preferred and why? What are their unique features? What about performance?

Tener
  • 5,280
  • 4
  • 25
  • 44
  • 2
    To answer a trivial point: I believe `mtl` is being incrementally phased out in favor of `transformers`. The current step in this process is replacing it with a thin wrapper around `transformers`, hence the dependency. – C. A. McCann Apr 26 '11 at 22:17
  • 5
    @camccann: `mtl` provides strictly more functionality than `transformers`, and is equivalent to `transformers`+`monads-fd` (which is now deprecated). `transformers` provides as much as possible in a Haskell-98 package, with extra functionality (mainly more instances) provided by `mtl`, or alternative packages if desired (e.g. `monads-tf`). – John L Apr 26 '11 at 22:31
  • @John L: Oh, so `mtl` is effectively replacing `monads-fd`, then? Thanks for the clarification, I'm a bit behind the times. – C. A. McCann Apr 26 '11 at 22:43
  • 3
    possible duplicate of [mtl, transformers, monads-fd, monadLib, and the paradox of choice](http://stackoverflow.com/questions/2769487/mtl-transformers-monads-fd-monadlib-and-the-paradox-of-choice) – Matt Fenwick Nov 28 '12 at 14:11
  • 4
    This link helped me understand mtl vs transformers http://www.haskell.org/haskellwiki/Monad_Transformer_Library – Brandon Cook Jul 13 '14 at 22:37
  • 3
    Darn interesting, useful question... – Marco Faustinelli Sep 02 '15 at 19:36

1 Answers1

18

The Haskell Platform specifies mtl and transformers as standard.

If you're unsure, you should just use mtl.

However, if you have a specific technical reason to look at the new libraries, they tend to address issues or add new features to mtl. monadLib in particular has some new features.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • 3
    What is the rationale behind choosing mtl by HP? – Tener Apr 26 '11 at 22:50
  • It is the oldest, most widely used, and best understood monad library. – Don Stewart Apr 26 '11 at 22:58
  • 2
    ...where, [going by Hackage dependencies](http://bifunctor.homelinux.net/~roel/hackage/packages/archive/revdeps-list.html), "most widely used" means something like "an order of magnitude more than all others besides `transformers` combined". – C. A. McCann Apr 26 '11 at 23:25
  • 9
    Moreover, the current mtl is effectively the monads-fd package renamed. it is largely compatible with the old mtl, while avoiding some of its duplications. (e.g. State is an alias for StateT) and it is built on top of the transformers package which provides a smaller Haskell 98 core for those who don't want to or can't step outside of the smaller language. – Edward Kmett Apr 26 '11 at 23:35