[Haskell-cafe] upgrading mtl1 to mtl2

Max Bolingbroke batterseapower at hotmail.com
Thu Feb 17 08:57:26 CET 2011


On 17 February 2011 07:28, Sebastian Fischer <fischer at nii.ac.jp> wrote:
> I must admit I still don't understand your exact problem. Could you help me
> with an example where using mtl2 requires an additional (Functor m)
> constraint that is not required when using mtl1?

I think the problem is that the mtl1 Functor instances looked like:

instance Monad m => Functor (ReaderT e m) where
  fmap = ...

But the mtl2/transformers instances look like:

instance Functor f => Functor (ReaderT e f) where
  fmap = ...

This is overall an improvement, but it does mean that if you relied on
getting "fmap" for e.g. a (ReaderT e m) monad from a (Monad m)
constraint with mtl1 then your code is now broken. You need to add
(Functor m) to your context for mtl2.

Naturally, this would not be a problem if Functor were a Monad superclass..

Cheers,
Max



More information about the Haskell-Cafe mailing list