Revision as of 07:25, 30 October 2010
- MTL - Monad Transformers Library: provides concrete monad transformers like and abstractions using multi-parameter type classes with functional dependencies likeStateT. Monads likeMonadStateand their transformer counterparts likeStateare distinct types and can be accessed uniformly only through a type class abstraction likeStateT. Because of the functional dependencies, MTL can currently (2010-03) only used in Hugs and GHC. MTL was the first implementation.MonadState
- The newer implementation is derived from the former one and is split into the following components:
- transformers: Provide only concrete transformers like . The monadStateTis only a type synonym forState s a. Thus bothStateT s Identity aandStatecan be accessed by the same methods likeStateTandput. However, this only works, ifgetis the top-most transformer in a monad transformer stack. This package is Haskell 98 and thus can be also used with JHC.StateT
- monads-fd: Provides the same type classes with functional dependencies like MTL. They allow using methods also forStatetransformers within a transformer stack.StateT
- monads-tf: Provides a different abstraction using type families. Unfortunately the names of
monads-tfclash, thus you can currently not import both packages in one package.
- transformers: Provide only concrete transformers like
1 How can I use MTL and transformers together?
Q: When I use ghc or ghci it complains about the same module names in mtl and transformers or monads-fd. How can I resolve these name clashes?
A: You can use the
-hide-package option of GHC. Cabal uses the
-hide-all-packages option and then explicitly makes every package visible with
2 Shall I use MTL or transformers?
Transformers is Haskell 98 and thus more portable.
3 How to move from MTL to transformers?
Many package using
MTL can be ported to
transformers with only slight modifications.
Modules require the
4 See also
- Monad Transformers Explained
- Monad Transformers Step by Step (PDF)
- All About Monads