#4159: move Monad and MonadFix instances for Either from mtl to base

John Meacham john at repetae.net
Wed Jun 30 19:05:31 EDT 2010

On Wed, Jun 30, 2010 at 12:13:07AM +0200, Claus Reinke wrote:
>>>> The proposal is to move the Monad and MonadFix instances for Either
>>>> (currently in the mtl package) to Control.Monad.Instances and
>>>> Control.Monad.Fix respectively (both in the base package).  The Monad
>>>> instance is still an orphan, to retain Haskell 98 compatibility, but the
>>>> MonadFix instance is together with its class.  The Error constraint is
>>>> removed from both instances, and the default definition of fail is used.
>>> -1, because the default definition of fail is error, which would
>>> render the Monad instance useless (unless I'm missing something?).
>> You would just use Left instead of 'fail' if you want to show failure 
>> in an Either value.
> a) you are suggesting to bypass a method of the proposed Monad
>    instance because it isn't useful, I am suggesting not to define a
>    Monad instance with unusable methods
> b) desugaring of pattern-match failure in Monads calls fail, not Left

However, there is no particular reason to associate 'Left' with failure.
Not having fail be 'Left' is a signifigant feature, not a limitation of
an Either instance.

A notable example would be a constraint solver, an algorithm might
attempt various solution strategies, even recursively calling itself on
subproblems and return the first solution found via 'Left', happily
jumping out of the whole computation with its prize. Strangely enough,
this means 'Left' indicates success and 'Right' indicates failure in
some sense. Defining 'fail' to be Left anything is clearly not correct. 

'Either' is a monad with a non-local return, _not_ necessarily an error
monad. The fact we can't come up with a sensible 'fail' for it is not an
indication of a problem with fail, or with either, but with simply
assuming incorrectly that a non-local return must mean failure, we
should have accepted what the type system was telling us and realized
that we shouldnt be giving it a fail :).

I do think we should make a dedicated failure monad though. It is also a
useful thing.


John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/

More information about the Libraries mailing list