transformers: remove instance MonadFix ExceptT and ErrorT
Ross Paterson
R.Paterson at city.ac.uk
Mon Aug 18 23:55:55 UTC 2014
On Tue, Aug 12, 2014 at 08:02:13PM -0400, David Feuer wrote:
> On Aug 12, 2014 7:50 PM, "Bertram Felgenhauer" <
> bertram.felgenhauer at googlemail.com> wrote:
> > I tend to agree that those MonadFix instances are not immensely useful.
>
> From my perspective as a generally ignorant person, I think these should be
> kept as long as
>
> 1. They satisfy the required laws and
> 2. No more useful instances can be written.
>
> That said, it might make sense to remove them if
>
> 1*. You can formulate a new law that distinguishes the instances you consider
> sensible from the ones you consider insensible.
There is a law that discriminates against the instances on strict monads,
known as right shrinking or right tightening:
mfix (\ (x,_) -> f x >>= rightM g) = mfix f >>= rightM g
where
rightM :: Monad m => (a -> m b) -> a -> m (a, b)
rightM f x = f x >>= \ y -> return (x, y)
A special case is
mfix (const e) = e
In do-notation, these become
do {rec {ss; x <- e}; ss'} = do {rec {ss}; x <- e; ss'}
(x not free in ss or e)
do {rec {x <- e}; ss} = do {x <- e; ss}
(x not free in e)
This law is pretty handy, but it was deliberately omitted from the axioms
for the MonadFix class, to permit the axioms for Maybe, Either, [] and IO.
The transformers package is just following those.
More information about the Libraries
mailing list