[Haskell-cafe] Monadic function fails as Nothing in Maybe context but as Exception in Either context.

Bryan Richter b at chreekat.net
Mon Nov 30 22:40:51 UTC 2015

On Mon, Nov 30, 2015 at 02:25:49PM -0800, Jeffrey Brown wrote:
> I've written a monadic function which in a Maybe context produces a Nothing
> when it fails (as intended), but in an Either context produces an Exception
> rather than a Left.

The Maybe instance for Monad overrides fail to be Nothing, but Either
instance does not. The default definition for fail is error.

The Except type has the behavior you are looking for, I believe — but
you may be better off avoiding the use of fail to begin with. :)


Also recommended for all your error-ful needs:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151130/865a0d3f/attachment.sig>

More information about the Haskell-Cafe mailing list