[Haskell-cafe] Monadic function fails as Nothing in Maybe context but as Exception in Either context.
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...
Size: 819 bytes
Desc: Digital signature
More information about the Haskell-Cafe