# Upgrading from MTL 1 to MTL 2

### From HaskellWiki

(Added another introductory paragraph, with links) |
m (Spelling correction) |
||

Line 1: | Line 1: | ||

Version 2 of the [[Monad Transformer Library]] introduced some | Version 2 of the [[Monad Transformer Library]] introduced some | ||

− | [[Incompatibilities between MTL 1 and MTL 2| | + | [[Incompatibilities between MTL 1 and MTL 2|incompatibilities]] |

relative to version 1. | relative to version 1. | ||

This page provides instructions for upgrading code written for | This page provides instructions for upgrading code written for |

## Latest revision as of 06:14, 25 December 2010

Version 2 of the Monad Transformer Library introduced some incompatibilities relative to version 1. This page provides instructions for upgrading code written for MTL 1 to work with MTL 2.

Many packages written for earlier versions of MTL build unchanged with version 2. Most of the remainder require only small changes to upgrade to it, though that will usually render them incompatible with version 1 without some CPP directives. Here are the fixes for common messages:

*Illegal instance declaration for Applicative (State a)*

- This usually means that the instance you're defining is now defined in the transformers package. You may wish to check it's the same, so you can just delete it.

*Could not deduce (Functor m) from the context (Monad m)arising from a use of fmap*

- This will be a situation where you're using a monad constructed with a transformer as a Functor. You can replace withfmapand the code will build with old and new versions of mtl.liftM

*Could not deduce (Functor m) from the context (Monad m)arising from the superclasses of an instance declaration*

- This will be another situation where you're using a monad constructed with a transformer as a Functor. You can replace the withMonad mto make it work with mtl-2, or add aFunctor mconstraint to make it work with old and new versions of mtl.Functor m

*Not in scope: data constructor State*

- The type is now a type synonym. You could replace theStatedata constructor with theStatefunction.state

*Not in scope: runState*

- You probably imported , which won't work now thatState(..)is a type synonym. You need to importStateandState. (That will work with old versions of mtl too.)runState

*Illegal instance declaration for Myclass (State Foo)*

- If you have a matching instance for , you can delete the instance forStateT. Otherwise you need to generalize your instance toState. If that's not possible, you may need to introduce aStateT.newtype