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
Monad Perhaps # | |
Functor Perhaps # | |
MonadFix Perhaps # | |
MonadFail Perhaps # | |
Applicative Perhaps # | |
Foldable Perhaps # | |
fold :: Monoid m => Perhaps m -> m # foldMap :: Monoid m => (a -> m) -> Perhaps a -> m # foldr :: (a -> b -> b) -> b -> Perhaps a -> b # foldr' :: (a -> b -> b) -> b -> Perhaps a -> b # foldl :: (b -> a -> b) -> b -> Perhaps a -> b # foldl' :: (b -> a -> b) -> b -> Perhaps a -> b # foldr1 :: (a -> a -> a) -> Perhaps a -> a # foldl1 :: (a -> a -> a) -> Perhaps a -> a # elem :: Eq a => a -> Perhaps a -> Bool # maximum :: Ord a => Perhaps a -> a # minimum :: Ord a => Perhaps a -> a # | |
Traversable Perhaps # | |
MonadZip Perhaps # | |
Alternative Perhaps # | |
MonadPlus Perhaps # | |
MonadPerhaps Perhaps # | |
Eq a => Eq (Perhaps a) # | |
Data a => Data (Perhaps a) # | |
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Perhaps a -> c (Perhaps a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Perhaps a) # toConstr :: Perhaps a -> Constr # dataTypeOf :: Perhaps a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Perhaps a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Perhaps a)) # gmapT :: (forall b. Data b => b -> b) -> Perhaps a -> Perhaps a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Perhaps a -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Perhaps a -> r # gmapQ :: (forall d. Data d => d -> u) -> Perhaps a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Perhaps a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Perhaps a -> m (Perhaps a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Perhaps a -> m (Perhaps a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Perhaps a -> m (Perhaps a) # | |
Ord a => Ord (Perhaps a) # | |
Read a => Read (Perhaps a) # | |
Show a => Show (Perhaps a) # | |
Generic (Perhaps a) # | |
Semigroup a => Semigroup (Perhaps a) # | |
Semigroup a => Monoid (Perhaps a) # | |
Generic1 Perhaps # | |
type Rep (Perhaps a) # | |
type Rep (Perhaps a) = D1 (MetaData "Perhaps" "Control.Monad.Perhaps" "perhaps-0-inplace" False) (C1 (MetaCons "Can" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)) :+: C1 (MetaCons "Can't" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Void))) | |
type Rep1 Perhaps # | |
type Rep1 Perhaps = D1 (MetaData "Perhaps" "Control.Monad.Perhaps" "perhaps-0-inplace" False) (C1 (MetaCons "Can" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1) :+: C1 (MetaCons "Can't" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Void))) |
This partial function can be used like fromJust
, but throws the user
error.
excuse :: (MonadPerhaps m, Exception e) => e -> m a #
Fail with an exception as an excuse instead of just a string.