Copyright | (c) Edward Kmett 2018 |
---|---|
License | BSD3 |
Maintainer | ekmett@gmail.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Maybe with an undisclosed error
This monad occupies the middle ground between Maybe
and Either
in that you can get out an informative error but aren't able to care
about its contents, except via bottoms.
Since bottoms are indistinguishable in pure code, one can view this
as morally the same as Maybe
, except when things go wrong, you can
pass along a complaint, rather than take what you'd get from
fromJust
.
>>>
import Control.Exception
>>>
let x = excuse Overflow :: Perhaps ()
Attempting to Show
a Perhaps
value is hazardous, as it will contain an embedded exception.
>>>
x
Can't *** Exception: arithmetic overflow
Recovery is possible as Can't
isn't strict in its argument.
>>>
x <|> Can ()
Can ()
>>>
x `seq` ()
()
Instances
believe :: Perhaps a -> a Source #
This partial function can be used like fromJust
, but throws the user
error.
excuse :: (MonadPerhaps m, Exception e) => e -> m a Source #
Fail with an exception as an excuse instead of just a string.