Difference between revisions of "Upgrading from MTL 1 to MTL 2"
Jump to navigation
Jump to search
(Added another introductory paragraph, with links) |
m (Minor formatting changes) |
||
(One intermediate revision by one other user not shown) | |||
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 |
||
Line 7: | Line 7: | ||
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: |
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)'' |
+ | * ''Illegal instance declaration for Applicative (State a)'' |
:This usually means that the instance you're defining is now defined in the [http://hackage.haskell.org/package/transformers transformers] package. You may wish to check it's the same, so you can just delete it. |
:This usually means that the instance you're defining is now defined in the [http://hackage.haskell.org/package/transformers 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)<br/>arising from a use of fmap'' |
+ | * ''Could not deduce (Functor m) from the context (Monad m)<br/>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 <hask>fmap</hask> with <hask>liftM</hask> and the code will build with old and new versions of mtl. |
:This will be a situation where you're using a monad constructed with a transformer as a Functor. You can replace <hask>fmap</hask> with <hask>liftM</hask> and the code will build with old and new versions of mtl. |
||
− | ''Could not deduce (Functor m) from the context (Monad m)<br/>arising from the superclasses of an instance declaration'' |
+ | * ''Could not deduce (Functor m) from the context (Monad m)<br/>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 <hask>Monad m</hask> with <hask>Functor m</hask> to make it work with mtl-2, or add a <hask>Functor m</hask> constraint to make it work with old and new versions of mtl. |
:This will be another situation where you're using a monad constructed with a transformer as a Functor. You can replace the <hask>Monad m</hask> with <hask>Functor m</hask> to make it work with mtl-2, or add a <hask>Functor m</hask> constraint to make it work with old and new versions of mtl. |
||
− | ''Not in scope: data constructor State'' |
+ | * ''Not in scope: data constructor State'' |
:The <hask>State</hask> type is now a type synonym. You could replace the <hask>State</hask> data constructor with the <hask>state</hask> function. |
:The <hask>State</hask> type is now a type synonym. You could replace the <hask>State</hask> data constructor with the <hask>state</hask> function. |
||
− | ''Not in scope: runState'' |
+ | * ''Not in scope: runState'' |
:You probably imported <hask>State(..)</hask>, which won't work now that <hask>State</hask> is a type synonym. You need to import <hask>State</hask> and <hask>runState</hask>. (That will work with old versions of mtl too.) |
:You probably imported <hask>State(..)</hask>, which won't work now that <hask>State</hask> is a type synonym. You need to import <hask>State</hask> and <hask>runState</hask>. (That will work with old versions of mtl too.) |
||
− | ''Illegal instance declaration for Myclass (State Foo)'' |
+ | * ''Illegal instance declaration for Myclass (State Foo)'' |
:If you have a matching instance for <hask>StateT</hask>, you can delete the instance for <hask>State</hask>. Otherwise you need to generalize your instance to <hask>StateT</hask>. If that's not possible, you may need to introduce a <hask>newtype</hask>. |
:If you have a matching instance for <hask>StateT</hask>, you can delete the instance for <hask>State</hask>. Otherwise you need to generalize your instance to <hask>StateT</hask>. If that's not possible, you may need to introduce a <hask>newtype</hask>. |
||
Latest revision as of 00:43, 9 April 2021
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
fmap
withliftM
and the code will build with old and new versions of mtl.
- 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
Monad m
withFunctor m
to make it work with mtl-2, or add aFunctor m
constraint to make it work with old and new versions of mtl.
- Not in scope: data constructor State
- The
State
type is now a type synonym. You could replace theState
data constructor with thestate
function.
- Not in scope: runState
- You probably imported
State(..)
, which won't work now thatState
is a type synonym. You need to importState
andrunState
. (That will work with old versions of mtl too.)
- Illegal instance declaration for Myclass (State Foo)
- If you have a matching instance for
StateT
, you can delete the instance forState
. Otherwise you need to generalize your instance toStateT
. If that's not possible, you may need to introduce anewtype
.