[Haskell-cafe] instance Monad (Either String) in Prelude or Data.Either?

Henning Thielemann lemming at henning-thielemann.de
Sat Sep 12 16:26:54 EDT 2009


Evan Laforge schrieb:
> On Fri, Sep 11, 2009 at 6:10 AM, Edward Kmett <ekmett at gmail.com> wrote:
>> Unfortunately, the instance of Monad for Either a is somewhat misguided in
>> Haskell.
>>
>> There is a spurious restraint that the Left value in your Either be a member
>> of some Error class, which was brought about by the deletion of MonadZero
>> from Haskell 98 (as part of the elimination of failure free patterns, and an
>> attempted simplification of the language).
> 
> I just tried it, and my own instance for Monad (Either String) (all
> I'm really interested in anyway) can coexist with the one for Error e
> => Monad (Either e).  But indeed, with the presence of fail, you can't
> write the general Monad (Either e) which "should" work.  And it does
> require FlexibleInstances.  I suppose as long as flexible instances
> aren't standard then even the String instance can't go in the Prelude.

Are you sure, that the instance cannot be defined in Haskell 98 using a
helper type class for the Char datatype?
  http://www.haskell.org/haskellwiki/List_instance



More information about the Haskell-Cafe mailing list