MTL, transformers, monads-fd, monadLib and the paradox of choice

Hackage has several packages for monodal transformers:

  • mtl : Monad Transformer Library
  • transformers : Concrete functor and monad transformers
  • monads-fd : Monad classes using functional dependencies
  • monads-tf : Monad classes using type families
  • monadLib : a collection of monad transformers.
  • mtl-tf : Monad Transformer Library using type families.
  • mmtl : Monad Modular Transformer Library.
  • mtlx : Monad type transformer library with type indices providing free copies.
  • compose-trans : Composite Monad Transformers

(and maybe I missed some)

Which one will we use?

mtl is the one on the Haskell platform, but I continue to hear from reddit that it is not being disclosed.

But what's wrong with choosing anyway, isn't that just a good thing?

Well, I saw how, for example, data access authors should have done all this to satisfy only the popular options:

  • data-accessor-monadLib library: Accessor functions for monads monadLib
  • data-accessor-monads-fd library: use Accessor to access state in monad-fd State monad class
  • data-accessor-monads-tf library: use Accessor to access state in monads-tf. A family of states like monad.
  • data-accessor-mtl library: use Accessor to access state in mtl State monad class
  • converter adapter data library: use Accessor to access state in State monad transformers

I assume that if this happens, and for example, several competing Arrow packages will develop, we will see something like: spoonklink-arrows-transformers, spoonklink-arrows-monadLib, spoonklink-tfArrows-transformers, spoonklink-tfArrows-monadLib, ...

And then I'm worried that if spoonklink is forked, Hackage will run out of disk space. :)

Questions:

  • Why are there so many monad transformer packages?
  • Why is mtl [considered] uncool?
  • What are the main differences?
  • Most of these seemingly competing packages were written by Andy Gill and are supported by Ross Paterson. Does this mean that these packages do not compete, but work in some way? And do Andy and Ross think any of their own packages are out of date?
  • Which one do you and you use?
+78
haskell monads monad-transformers
May 04 '10 at 22:51
source share
3 answers

A bouquet of them is almost completely equivalent:

  • mtl uses GHC extensions, but transformers Haskell 98.
  • monads-fd and monads-tf are complementary to transformers using functional dependencies and type families respectively, both provide functionality in mtl that is not present in transformers .
  • mtl-tf mtl overridden using type families.

Essentially mtl == transformers ++ monads-fd , mtl-tf == transformers ++ monads-tf . The improved portability and modularity of transformers and related packages is explained by why mtl is not suitable these days.

mmtl and mtlx both seem similar and / or mtl based, with API differences and additional features.

MonadLib seems to have a slightly different relevance, but I'm not familiar with it directly. It also seems to use many GHC extensions, more than others.

A brief overview of compose-trans seems more like metaprogramming material for creating monad transformers. He claims to be compatible with Control.Monad.Trans , which ... I think it means mtl ?

Anyway, I would suggest the following solution algorithm:

  • Do you need standard monads for a new project? Use transformers and co., Help us lay mtl to rest.
  • Are you already using mtl in a big project? transformers not fully compatible, but no one will kill you for not switching.
  • Does one of the other packages provide unusual functionality? You can also use it, rather than folding your own.
  • Still unsatisfied? Throw them all away, download category-extras and solve all the world's problems with a page with half obscure abstract nonsense strike> exciting general code.
+63
May 04 '10 at 23:37
source share

Presently? You should mtl use mtl . What happens is that the transformers library is exposed from MTL in such a way that monads-fd and monads-tf can coexist peacefully, but finally check that this is not the case.

When that happens, you can import monads-fd and transformers and get (almost) the same interface, except that State , etc. will be an alias for StateT .

Therefore, I write in mtl , but I do not rely on State, Reader, etc. currently data , as they will be replaced by type s.

MonadLib is another alternative that Iavor is working on, which can be safely used since it does not use module names with others, but has a rather different usage pattern.

+20
May 05 '10 at 12:28 a.m.
source share

At the end of 2010, factoring by Edward Kemt in his answer was completed. Its final result was monads-fd, built on transformers, becoming the second version of mtl. As a consequence of the ubiquity of mtl, monads-tf has never come across. At the beginning of 2017, mtl and transformers are the only monad transformer libraries that are widely used.

+7
Mar 04 '17 at 23:48 on
source share



All Articles