Difference between revisions of "Monad Transformer Library"

From HaskellWiki
Jump to navigation Jump to search
(Add link to incompatibilities page)
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
 
Version 2 of the MTL has some small
 
Version 2 of the MTL has some small
 
[[Incompatibilities between MTL 1 and MTL 2|incompatibilities]]
 
[[Incompatibilities between MTL 1 and MTL 2|incompatibilities]]
with version 1.
+
relative to version 1.
See [[Upgrading from MTL 1 to MTL 2|this page]] for instructions on how
+
See "[[Upgrading from MTL 1 to MTL 2]]" for instructions on how
 
to make code written for version 1 work with version 2.
 
to make code written for version 1 work with version 2.
   
  +
=== History ===
  +
  +
Once upon a time, mtl was a standalone monad transformer library, that defined monad transformers and constructor classes for them. The constructor classes were frequently [[Multi-parameter type class|multiparameter classes]] with [[functional dependencies]].
  +
  +
Some time later, [[type families]] were invented, and were found to solve several of the same problems as multiparameter classes with functional dependencies. A package named mtl-tf was developed, to provide the functionality of mtl but using type families instead.
  +
  +
However, there was a lot of duplicated code involved: mtl and mtl-tf both defined their own monad transformers, so they didn't work well together. The constructor classes were different by necessity, because they used different technology, but the data types themselves were duplicated for no reason.
  +
  +
Hence, transformers was developed: a library that used no extensions to Haskell98 and only defined the transformer types themselves, so that more advanced libraries could share them as a base. monads-fd and monads-tf were developed as libraries that took transformers from the transformers package and defined the constructor classes over the top of them, monads-fd using multiparameter typeclasses with functional dependencies and monads-tf using type families.
  +
  +
The technological problem was then solved, but unfortunately the original mtl library already had a lot of traction: it had existed for longer and was in widespread use. So instead of encouraging people to switch libraries, the maintainers switched implementations instead: they decided to merge monads-fd and mtl into a single library.
  +
  +
Since the mtl name was far better known, monads-fd was deprecated, and mtl was switched to depend on transformers. Since transformers had some stylistic differences as well, this resulted in some API changes (see above).
  +
  +
As it now stands, transformers is the "standard" monad transformer library, but mtl and monads-tf both act as extensions of it. monads-tf is not very well-used, which is unfortunate as it's quite a nice approach.
  +
  +
=== See also ===
  +
  +
* [http://stackoverflow.com/questions/2769487/mtl-transformers-monads-fd-monadlib-and-the-paradox-of-choice Stack Overflow: mtl, transformers, monads-fd, monadLib, and the paradox of choice]
  +
* [http://www.haskell.org/pipermail/libraries/2010-September/014281.html libraries mailing list: Haskell Platform Proposal: add transformers and revise the mtl package to depend on it]
   
 
[[Category:Monad]]
 
[[Category:Monad]]

Latest revision as of 17:04, 21 December 2012

The MTL provides a selection of monads and their transformer variants along with type classes that allow uniform handling of a base monad and its transformer.

See the package on Hackage.

Version 2 of the MTL has some small incompatibilities relative to version 1. See "Upgrading from MTL 1 to MTL 2" for instructions on how to make code written for version 1 work with version 2.

History

Once upon a time, mtl was a standalone monad transformer library, that defined monad transformers and constructor classes for them. The constructor classes were frequently multiparameter classes with functional dependencies.

Some time later, type families were invented, and were found to solve several of the same problems as multiparameter classes with functional dependencies. A package named mtl-tf was developed, to provide the functionality of mtl but using type families instead.

However, there was a lot of duplicated code involved: mtl and mtl-tf both defined their own monad transformers, so they didn't work well together. The constructor classes were different by necessity, because they used different technology, but the data types themselves were duplicated for no reason.

Hence, transformers was developed: a library that used no extensions to Haskell98 and only defined the transformer types themselves, so that more advanced libraries could share them as a base. monads-fd and monads-tf were developed as libraries that took transformers from the transformers package and defined the constructor classes over the top of them, monads-fd using multiparameter typeclasses with functional dependencies and monads-tf using type families.

The technological problem was then solved, but unfortunately the original mtl library already had a lot of traction: it had existed for longer and was in widespread use. So instead of encouraging people to switch libraries, the maintainers switched implementations instead: they decided to merge monads-fd and mtl into a single library.

Since the mtl name was far better known, monads-fd was deprecated, and mtl was switched to depend on transformers. Since transformers had some stylistic differences as well, this resulted in some API changes (see above).

As it now stands, transformers is the "standard" monad transformer library, but mtl and monads-tf both act as extensions of it. monads-tf is not very well-used, which is unfortunate as it's quite a nice approach.

See also