Difference between revisions of "Refactoring the MTL"

From HaskellWiki
Jump to: navigation, search
(add another note about experiment)
(moved to another wiki)
 
Line 1: Line 1:
Ganesh and Ross propose that the next version of the [http://hackage.haskell.org/package/mtl mtl] package should be a compatibility layer over the [http://hackage.haskell.org/package/transformers transformers] and [http://hackage.haskell.org/package/monads-fd monads-fd] packages. A draft of this compatibility layer is available at http://urchin.earth.li/darcs/ganesh/mtl-compat .
 
  +
moved to http://trac.haskell.org/haskell-platform/wiki/Proposals/transformers
 
== Rationale ==
 
 
Monad transformers are widely used, but the MTL implementation is tied to functional dependencies, whose future is in doubt. Many people want to try out versions based on type functions, or without using advanced type classes at all, but their interfaces will then be incompatible with libraries using mtl.
 
 
The idea is to factor out the monad transformers as a Haskell 98 package, which can be used by itself or with type classes based on either functional dependencies or type functions. Interfaces referring to the monad transformers would be compatible across the different libraries.
 
 
== Structure ==
 
 
The current mtl is to be replaced with three packages.
 
 
* [http://hackage.haskell.org/package/transformers transformers] is a Haskell 98 package containing the identity monad (Control.Monad.Identity), transformer classes (Control.Monad.Trans) and concrete monad transformers with code to lift operators (Control.Monad.Trans.*). There are also a number of changes in comparison with mtl:
 
:* simple monads like <hask>State s</hask> are now aliases for <hask>StateT s Identity</hask>.
 
:* Functor instances for monad transformers no longer require Monad where Functor is sufficient.
 
:* instances of <hask>Applicative</hask> and <hask>Alternative</hask> have been added as appropriate.
 
:This package can be used on its own, or with packages adding type classes.
 
 
* [http://hackage.haskell.org/package/monads-fd monads-fd] depends on transformers and adds type classes using functional dependencies.
 
 
* The [http://urchin.earth.li/darcs/ganesh/mtl-compat new version of mtl] depends on transformers and monads-fd, and is almost a compatible replacement for the current version, except for the differences listed above.
 
 
== Outstanding issues ==
 
 
* The [http://hackage.haskell.org/package/monads-fd monads-fd] and [http://hackage.haskell.org/package/monads-tf monads-tf] packages use the same names for modules with different interfaces. Although monads-tf is not part of this proposal, should the modules in it or both the packages be renamed, and if so to what?
 
 
* Should we delete all but the Class modules from monads-fd (and monads-tf)? That would mean that code using transformers and monads-fd directly would have to import both <hask>Control.Monad.Trans.State</hask> and <hask>Control.Monad.State.Class</hask>, where code using the mtl would have to import just <hask>Control.Monad.State</hask>.
 
 
* The module <hask>Control.Monad.Cont.Class</hask> is Haskell 98. Should it be moved out of monads-fd, and if so where?
 
 
== Transition issues ==
 
 
A [http://www.haskell.org/pipermail/libraries/2009-March/011471.html survey] of Hackage in March 2009 found 19 packages that would fail to compile with the proposed new version of mtl. Note that this survey excluded packages that depend (directly or indirectly) on gtk2hs or any other packages not available on hackage. It also excluded packages that already declare an appropriate upper bound on their mtl dependency.
 
 
Those packages will need changes to compile with the new version of mtl, but need not switch to transformers and monads-fd (or just transformers) until later. These packages could add a dependency constraint <code>mtl < 2</code> now, to avoid being built with the new version when it appears. The affected packages are listed below.
 
 
Different dependencies, extra instances:
 
 
* [http://hackage.haskell.org/package/monad-param/blogination blogination]: Functor instances depending on Functor, instance collision Applicative/Alternative ErrorT
 
* [http://hackage.haskell.org/package/category-extras category-extras]: Functor instances depending on Functor
 
* [http://hackage.haskell.org/package/monad-param/cgi cgi]: Functor instances depending on Functor
 
* [http://hackage.haskell.org/package/monad-param/encoding encoding]: instance collision: Monad Either
 
* [http://hackage.haskell.org/package/monad-param/logict logict]: instance collision: Applicative Identity (will be superfluous: same as instance in transformers)
 
* [http://hackage.haskell.org/package/monad-param monad-param]: Functor instances depending on Functor
 
* [http://hackage.haskell.org/package/monad-param/mueval mueval]: Functor instances depending on Functor
 
* [http://hackage.haskell.org/package/xcb-types xcb-types]: instance collision: Applicative/Alternative ReaderT (will be superfluous: same as instance in transformers; version 0.5.1.1 has mtl < 1.2)
 
* [http://hackage.haskell.org/package/xmonad-contrib xmonad-contrib]: instance collision: Error [a]:
 
 
Data constructors for basic monad classes:
 
 
* [http://hackage.haskell.org/package/monad-param/FileManip FileManip]: Missing data constructor: State
 
* [http://hackage.haskell.org/package/HAppS-Server HAppS-Server]: Missing data constructor: Reader
 
* [http://hackage.haskell.org/package/monad-param/HaLeX HaLeX]: Missing data constructor: State
 
* [http://hackage.haskell.org/package/monad-param/LambdaHack LambdaHack]: Missing data constructor: State (version 0.1.20090606 has mtl < 2)
 
* [http://hackage.haskell.org/package/monad-param/lambdabot lambdabot]: Missing data constructor: State
 
* [http://hackage.haskell.org/package/open-witness open-witness]: Missing data constructor: State
 
 
Instances for basic monad classes that are now type synonyms:
 
 
* [http://hackage.haskell.org/package/applicative-extras applicative-extras]: instance Applicative (State a) (will be superfluous: same as instance in transformers)
 
* [http://hackage.haskell.org/package/monad-param/derive derive]: instance Applicative (Writer a) (will be superfluous: same as instance in transformers)
 
* [http://hackage.haskell.org/package/random-fu random-fu]: instance MonadRandom (State StdGen) (will be superfluous: same instance as declared for StateT)
 
* [http://hackage.haskell.org/package/monad-param/yhccore yhccore]: instance UniqueIdM (State a) (could be trivially generalized to StateT)
 

Latest revision as of 14:42, 18 November 2009

moved to http://trac.haskell.org/haskell-platform/wiki/Proposals/transformers