perhaps-0: Perhaps, a monad

Copyright(c) Edward Kmett 2018
LicenseBSD3
Maintainerekmett@gmail.com
Stabilitystable
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Control.Monad.Perhaps

Contents

Description

 
Synopsis

Maybe with an undisclosed error

data Perhaps a #

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` ()
()

Constructors

Can a 
Can't Void 
Instances
Monad Perhaps # 
Instance details

Methods

(>>=) :: Perhaps a -> (a -> Perhaps b) -> Perhaps b #

(>>) :: Perhaps a -> Perhaps b -> Perhaps b #

return :: a -> Perhaps a #

fail :: String -> Perhaps a #

Functor Perhaps # 
Instance details

Methods

fmap :: (a -> b) -> Perhaps a -> Perhaps b #

(<$) :: a -> Perhaps b -> Perhaps a #

MonadFix Perhaps # 
Instance details

Methods

mfix :: (a -> Perhaps a) -> Perhaps a #

MonadFail Perhaps # 
Instance details

Methods

fail :: String -> Perhaps a #

Applicative Perhaps # 
Instance details

Methods

pure :: a -> Perhaps a #

(<*>) :: Perhaps (a -> b) -> Perhaps a -> Perhaps b #

liftA2 :: (a -> b -> c) -> Perhaps a -> Perhaps b -> Perhaps c #

(*>) :: Perhaps a -> Perhaps b -> Perhaps b #

(<*) :: Perhaps a -> Perhaps b -> Perhaps a #

Foldable Perhaps # 
Instance details

Methods

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 #

toList :: Perhaps a -> [a] #

null :: Perhaps a -> Bool #

length :: Perhaps a -> Int #

elem :: Eq a => a -> Perhaps a -> Bool #

maximum :: Ord a => Perhaps a -> a #

minimum :: Ord a => Perhaps a -> a #

sum :: Num a => Perhaps a -> a #

product :: Num a => Perhaps a -> a #

Traversable Perhaps # 
Instance details

Methods

traverse :: Applicative f => (a -> f b) -> Perhaps a -> f (Perhaps b) #

sequenceA :: Applicative f => Perhaps (f a) -> f (Perhaps a) #

mapM :: Monad m => (a -> m b) -> Perhaps a -> m (Perhaps b) #

sequence :: Monad m => Perhaps (m a) -> m (Perhaps a) #

MonadZip Perhaps # 
Instance details

Methods

mzip :: Perhaps a -> Perhaps b -> Perhaps (a, b) #

mzipWith :: (a -> b -> c) -> Perhaps a -> Perhaps b -> Perhaps c #

munzip :: Perhaps (a, b) -> (Perhaps a, Perhaps b) #

Alternative Perhaps # 
Instance details

Methods

empty :: Perhaps a #

(<|>) :: Perhaps a -> Perhaps a -> Perhaps a #

some :: Perhaps a -> Perhaps [a] #

many :: Perhaps a -> Perhaps [a] #

MonadPlus Perhaps # 
Instance details

Methods

mzero :: Perhaps a #

mplus :: Perhaps a -> Perhaps a -> Perhaps a #

MonadPerhaps Perhaps # 
Instance details

Methods

perhaps :: Perhaps a -> Perhaps a #

excuse :: Exception e => e -> Perhaps a #

Eq a => Eq (Perhaps a) # 
Instance details

Methods

(==) :: Perhaps a -> Perhaps a -> Bool #

(/=) :: Perhaps a -> Perhaps a -> Bool #

Data a => Data (Perhaps a) # 
Instance details

Methods

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) # 
Instance details

Methods

compare :: Perhaps a -> Perhaps a -> Ordering #

(<) :: Perhaps a -> Perhaps a -> Bool #

(<=) :: Perhaps a -> Perhaps a -> Bool #

(>) :: Perhaps a -> Perhaps a -> Bool #

(>=) :: Perhaps a -> Perhaps a -> Bool #

max :: Perhaps a -> Perhaps a -> Perhaps a #

min :: Perhaps a -> Perhaps a -> Perhaps a #

Read a => Read (Perhaps a) # 
Instance details
Show a => Show (Perhaps a) # 
Instance details

Methods

showsPrec :: Int -> Perhaps a -> ShowS #

show :: Perhaps a -> String #

showList :: [Perhaps a] -> ShowS #

Generic (Perhaps a) # 
Instance details

Associated Types

type Rep (Perhaps a) :: * -> * #

Methods

from :: Perhaps a -> Rep (Perhaps a) x #

to :: Rep (Perhaps a) x -> Perhaps a #

Semigroup a => Semigroup (Perhaps a) # 
Instance details

Methods

(<>) :: Perhaps a -> Perhaps a -> Perhaps a #

sconcat :: NonEmpty (Perhaps a) -> Perhaps a #

stimes :: Integral b => b -> Perhaps a -> Perhaps a #

Semigroup a => Monoid (Perhaps a) # 
Instance details

Methods

mempty :: Perhaps a #

mappend :: Perhaps a -> Perhaps a -> Perhaps a #

mconcat :: [Perhaps a] -> Perhaps a #

Generic1 Perhaps # 
Instance details

Associated Types

type Rep1 Perhaps :: k -> * #

Methods

from1 :: Perhaps a -> Rep1 Perhaps a #

to1 :: Rep1 Perhaps a -> Perhaps a #

type Rep (Perhaps a) # 
Instance details
type Rep1 Perhaps # 
Instance details

believe :: Perhaps a -> a #

This partial function can be used like fromJust, but throws the user error.

mayhap :: Perhaps a -> Maybe a #

Transformer

newtype PerhapsT m a #

Constructors

PerhapsT 

Fields

Instances
MonadTrans PerhapsT # 
Instance details

Methods

lift :: Monad m => m a -> PerhapsT m a #

MonadWriter w m => MonadWriter w (PerhapsT m) # 
Instance details

Methods

writer :: (a, w) -> PerhapsT m a #

tell :: w -> PerhapsT m () #

listen :: PerhapsT m a -> PerhapsT m (a, w) #

pass :: PerhapsT m (a, w -> w) -> PerhapsT m a #

MonadState s m => MonadState s (PerhapsT m) # 
Instance details

Methods

get :: PerhapsT m s #

put :: s -> PerhapsT m () #

state :: (s -> (a, s)) -> PerhapsT m a #

MonadReader r m => MonadReader r (PerhapsT m) # 
Instance details

Methods

ask :: PerhapsT m r #

local :: (r -> r) -> PerhapsT m a -> PerhapsT m a #

reader :: (r -> a) -> PerhapsT m a #

Monad m => Monad (PerhapsT m) # 
Instance details

Methods

(>>=) :: PerhapsT m a -> (a -> PerhapsT m b) -> PerhapsT m b #

(>>) :: PerhapsT m a -> PerhapsT m b -> PerhapsT m b #

return :: a -> PerhapsT m a #

fail :: String -> PerhapsT m a #

Functor m => Functor (PerhapsT m) # 
Instance details

Methods

fmap :: (a -> b) -> PerhapsT m a -> PerhapsT m b #

(<$) :: a -> PerhapsT m b -> PerhapsT m a #

MonadFix m => MonadFix (PerhapsT m) # 
Instance details

Methods

mfix :: (a -> PerhapsT m a) -> PerhapsT m a #

Monad m => MonadFail (PerhapsT m) # 
Instance details

Methods

fail :: String -> PerhapsT m a #

Monad m => Applicative (PerhapsT m) # 
Instance details

Methods

pure :: a -> PerhapsT m a #

(<*>) :: PerhapsT m (a -> b) -> PerhapsT m a -> PerhapsT m b #

liftA2 :: (a -> b -> c) -> PerhapsT m a -> PerhapsT m b -> PerhapsT m c #

(*>) :: PerhapsT m a -> PerhapsT m b -> PerhapsT m b #

(<*) :: PerhapsT m a -> PerhapsT m b -> PerhapsT m a #

Foldable m => Foldable (PerhapsT m) # 
Instance details

Methods

fold :: Monoid m0 => PerhapsT m m0 -> m0 #

foldMap :: Monoid m0 => (a -> m0) -> PerhapsT m a -> m0 #

foldr :: (a -> b -> b) -> b -> PerhapsT m a -> b #

foldr' :: (a -> b -> b) -> b -> PerhapsT m a -> b #

foldl :: (b -> a -> b) -> b -> PerhapsT m a -> b #

foldl' :: (b -> a -> b) -> b -> PerhapsT m a -> b #

foldr1 :: (a -> a -> a) -> PerhapsT m a -> a #

foldl1 :: (a -> a -> a) -> PerhapsT m a -> a #

toList :: PerhapsT m a -> [a] #

null :: PerhapsT m a -> Bool #

length :: PerhapsT m a -> Int #

elem :: Eq a => a -> PerhapsT m a -> Bool #

maximum :: Ord a => PerhapsT m a -> a #

minimum :: Ord a => PerhapsT m a -> a #

sum :: Num a => PerhapsT m a -> a #

product :: Num a => PerhapsT m a -> a #

Traversable m => Traversable (PerhapsT m) # 
Instance details

Methods

traverse :: Applicative f => (a -> f b) -> PerhapsT m a -> f (PerhapsT m b) #

sequenceA :: Applicative f => PerhapsT m (f a) -> f (PerhapsT m a) #

mapM :: Monad m0 => (a -> m0 b) -> PerhapsT m a -> m0 (PerhapsT m b) #

sequence :: Monad m0 => PerhapsT m (m0 a) -> m0 (PerhapsT m a) #

MonadZip m => MonadZip (PerhapsT m) # 
Instance details

Methods

mzip :: PerhapsT m a -> PerhapsT m b -> PerhapsT m (a, b) #

mzipWith :: (a -> b -> c) -> PerhapsT m a -> PerhapsT m b -> PerhapsT m c #

munzip :: PerhapsT m (a, b) -> (PerhapsT m a, PerhapsT m b) #

MonadIO m => MonadIO (PerhapsT m) # 
Instance details

Methods

liftIO :: IO a -> PerhapsT m a #

Monad m => Alternative (PerhapsT m) # 
Instance details

Methods

empty :: PerhapsT m a #

(<|>) :: PerhapsT m a -> PerhapsT m a -> PerhapsT m a #

some :: PerhapsT m a -> PerhapsT m [a] #

many :: PerhapsT m a -> PerhapsT m [a] #

Monad m => MonadPlus (PerhapsT m) # 
Instance details

Methods

mzero :: PerhapsT m a #

mplus :: PerhapsT m a -> PerhapsT m a -> PerhapsT m a #

MonadCont m => MonadCont (PerhapsT m) # 
Instance details

Methods

callCC :: ((a -> PerhapsT m b) -> PerhapsT m a) -> PerhapsT m a #

Monad m => MonadPerhaps (PerhapsT m) # 
Instance details

Methods

perhaps :: Perhaps a -> PerhapsT m a #

excuse :: Exception e => e -> PerhapsT m a #

Functor m => Generic1 (PerhapsT m :: * -> *) # 
Instance details

Associated Types

type Rep1 (PerhapsT m) :: k -> * #

Methods

from1 :: PerhapsT m a -> Rep1 (PerhapsT m) a #

to1 :: Rep1 (PerhapsT m) a -> PerhapsT m a #

Eq (m (Perhaps a)) => Eq (PerhapsT m a) # 
Instance details

Methods

(==) :: PerhapsT m a -> PerhapsT m a -> Bool #

(/=) :: PerhapsT m a -> PerhapsT m a -> Bool #

(Data (m (Perhaps a)), Typeable m, Typeable a) => Data (PerhapsT m a) # 
Instance details

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PerhapsT m a -> c (PerhapsT m a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (PerhapsT m a) #

toConstr :: PerhapsT m a -> Constr #

dataTypeOf :: PerhapsT m a -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (PerhapsT m a)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PerhapsT m a)) #

gmapT :: (forall b. Data b => b -> b) -> PerhapsT m a -> PerhapsT m a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PerhapsT m a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PerhapsT m a -> r #

gmapQ :: (forall d. Data d => d -> u) -> PerhapsT m a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PerhapsT m a -> u #

gmapM :: Monad m0 => (forall d. Data d => d -> m0 d) -> PerhapsT m a -> m0 (PerhapsT m a) #

gmapMp :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> PerhapsT m a -> m0 (PerhapsT m a) #

gmapMo :: MonadPlus m0 => (forall d. Data d => d -> m0 d) -> PerhapsT m a -> m0 (PerhapsT m a) #

Ord (m (Perhaps a)) => Ord (PerhapsT m a) # 
Instance details

Methods

compare :: PerhapsT m a -> PerhapsT m a -> Ordering #

(<) :: PerhapsT m a -> PerhapsT m a -> Bool #

(<=) :: PerhapsT m a -> PerhapsT m a -> Bool #

(>) :: PerhapsT m a -> PerhapsT m a -> Bool #

(>=) :: PerhapsT m a -> PerhapsT m a -> Bool #

max :: PerhapsT m a -> PerhapsT m a -> PerhapsT m a #

min :: PerhapsT m a -> PerhapsT m a -> PerhapsT m a #

Read (m (Perhaps a)) => Read (PerhapsT m a) # 
Instance details
Show (m (Perhaps a)) => Show (PerhapsT m a) # 
Instance details

Methods

showsPrec :: Int -> PerhapsT m a -> ShowS #

show :: PerhapsT m a -> String #

showList :: [PerhapsT m a] -> ShowS #

Generic (PerhapsT m a) # 
Instance details

Associated Types

type Rep (PerhapsT m a) :: * -> * #

Methods

from :: PerhapsT m a -> Rep (PerhapsT m a) x #

to :: Rep (PerhapsT m a) x -> PerhapsT m a #

type Rep1 (PerhapsT m :: * -> *) # 
Instance details
type Rep1 (PerhapsT m :: * -> *) = D1 (MetaData "PerhapsT" "Control.Monad.Perhaps" "perhaps-0-inplace" True) (C1 (MetaCons "PerhapsT" PrefixI True) (S1 (MetaSel (Just "runPerhapsT") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (m :.: Rec1 Perhaps)))
type Rep (PerhapsT m a) # 
Instance details
type Rep (PerhapsT m a) = D1 (MetaData "PerhapsT" "Control.Monad.Perhaps" "perhaps-0-inplace" True) (C1 (MetaCons "PerhapsT" PrefixI True) (S1 (MetaSel (Just "runPerhapsT") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (m (Perhaps a)))))

Class

class MonadPlus m => MonadPerhaps m where #

Methods

perhaps :: Perhaps a -> m a #

This is a monad homomorphism

perhaps :: (m ~ t n, MonadTrans t, MonadPerhaps n) => Perhaps a -> m a #

This is a monad homomorphism

excuse :: Exception e => e -> m a #

Fail with an exception as an excuse instead of just a string.

Instances
MonadPerhaps Perhaps # 
Instance details

Methods

perhaps :: Perhaps a -> Perhaps a #

excuse :: Exception e => e -> Perhaps a #

Monad m => MonadPerhaps (PerhapsT m) # 
Instance details

Methods

perhaps :: Perhaps a -> PerhapsT m a #

excuse :: Exception e => e -> PerhapsT m a #

MonadPerhaps m => MonadPerhaps (IdentityT m) # 
Instance details

Methods

perhaps :: Perhaps a -> IdentityT m a #

excuse :: Exception e => e -> IdentityT m a #

MonadPerhaps m => MonadPerhaps (StateT s m) # 
Instance details

Methods

perhaps :: Perhaps a -> StateT s m a #

excuse :: Exception e => e -> StateT s m a #

MonadPerhaps m => MonadPerhaps (StateT s m) # 
Instance details

Methods

perhaps :: Perhaps a -> StateT s m a #

excuse :: Exception e => e -> StateT s m a #

(MonadPerhaps m, Monoid w) => MonadPerhaps (WriterT w m) # 
Instance details

Methods

perhaps :: Perhaps a -> WriterT w m a #

excuse :: Exception e => e -> WriterT w m a #

(MonadPerhaps m, Monoid w) => MonadPerhaps (WriterT w m) # 
Instance details

Methods

perhaps :: Perhaps a -> WriterT w m a #

excuse :: Exception e => e -> WriterT w m a #

MonadPerhaps m => MonadPerhaps (ReaderT r m) # 
Instance details

Methods

perhaps :: Perhaps a -> ReaderT r m a #

excuse :: Exception e => e -> ReaderT r m a #

(MonadPerhaps m, Monoid w) => MonadPerhaps (RWST r w s m) # 
Instance details

Methods

perhaps :: Perhaps a -> RWST r w s m a #

excuse :: Exception e => e -> RWST r w s m a #

(MonadPerhaps m, Monoid w) => MonadPerhaps (RWST r w s m) # 
Instance details

Methods

perhaps :: Perhaps a -> RWST r w s m a #

excuse :: Exception e => e -> RWST r w s m a #

Combinators

mapPerhapsT :: (m (Perhaps a) -> n (Perhaps b)) -> PerhapsT m a -> PerhapsT n b #

Transform the computation inside a PerhapsT.

liftCallCC :: CallCC m (Perhaps a) (Perhaps b) -> CallCC (PerhapsT m) a b #

Lift a callCC operation to the new monad.

liftCatch :: Catch e m (Perhaps a) -> Catch e (PerhapsT m) a #

Lift a catchE operation to the new monad.

liftListen :: Monad m => Listen w m (Perhaps a) -> Listen w (PerhapsT m) a #

Lift a listen operation to the new monad.

liftPass :: Monad m => Pass w m (Perhaps a) -> Pass w (PerhapsT m) a #

Lift a pass operation to the new monad.