automaton-1.3: Effectful streams and automata in initial encoding
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Automaton.Trans.Maybe

Description

An Automaton with Maybe or MaybeT in its monad stack can terminate execution at any step.

Synopsis

Documentation

exit :: Monad m => Automaton (MaybeT m) a b Source #

Throw the exception immediately.

exitWhen :: Monad m => (a -> Bool) -> Automaton (MaybeT m) a a Source #

Throw the exception when the condition becomes true on the input.

exitIf :: Monad m => Automaton (MaybeT m) Bool () Source #

Exit when the incoming value is True.

maybeExit :: Monad m => Automaton (MaybeT m) (Maybe a) a Source #

Just a is passed along, Nothing causes the whole Automaton to exit.

inMaybeT :: Monad m => Automaton (MaybeT m) (Maybe a) a Source #

Embed a Maybe value in the MaybeT layer. Identical to maybeExit.

untilMaybe :: Monad m => Automaton m a b -> Automaton m b Bool -> Automaton (MaybeT m) a b Source #

Run the first automaton until the second one produces True from the output of the first.

catchMaybe :: (Functor m, Monad m) => Automaton (MaybeT m) a b -> Automaton m a b -> Automaton m a b Source #

When an exception occurs in the first automaton, the second automaton is executed from there.

exceptToMaybeS :: (Functor m, Monad m) => Automaton (ExceptT e m) a b -> Automaton (MaybeT m) a b Source #

Convert exceptions into Nothing, discarding the exception value.

listToMaybeS :: (Functor m, Monad m) => [b] -> Automaton (MaybeT m) a b Source #

Converts a list to an Automaton in MaybeT, which outputs an element of the list at each step, throwing Nothing when the list ends.

runMaybeS :: (Functor m, Monad m) => Automaton (MaybeT m) a b -> Automaton m a (Maybe b) Source #

Remove the MaybeT layer by outputting Nothing when the exception occurs.

The current state is then tested again on the next input.

reactimateMaybe :: (Functor m, Monad m) => Automaton (MaybeT m) () () -> m () Source #

reactimates an Automaton in the MaybeT monad until it throws Nothing.

embed_ :: (Functor m, Monad m) => Automaton m a () -> [a] -> m () Source #

Run an Automaton fed from a list, discarding results. Useful when one needs to combine effects and streams (i.e., for testing purposes).

newtype MaybeT (m :: Type -> Type) a #

The parameterizable maybe monad, obtained by composing an arbitrary monad with the Maybe monad.

Computations are actions that may produce a value or exit.

The return function yields a computation that produces that value, while >>= sequences two subcomputations, exiting if either computation does.

Constructors

MaybeT 

Fields

Instances

Instances details
MMonad MaybeT 
Instance details

Defined in Control.Monad.Morph

Methods

embed :: forall (n :: Type -> Type) m b. Monad n => (forall a. m a -> MaybeT n a) -> MaybeT m b -> MaybeT n b #

MonadTrans MaybeT 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

MFunctor MaybeT 
Instance details

Defined in Control.Monad.Morph

Methods

hoist :: forall m n (b :: k). Monad m => (forall a. m a -> n a) -> MaybeT m b -> MaybeT n b #

MonadSplit g m => MonadSplit g (MaybeT m) 
Instance details

Defined in Control.Monad.Random.Class

Methods

getSplit :: MaybeT m g #

Functor m => Generic1 (MaybeT m :: Type -> Type) 
Instance details

Defined in Control.Monad.Trans.Maybe

Associated Types

type Rep1 (MaybeT m) :: k -> Type #

Methods

from1 :: forall (a :: k). MaybeT m a -> Rep1 (MaybeT m) a #

to1 :: forall (a :: k). Rep1 (MaybeT m) a -> MaybeT m a #

MonadInterleave m => MonadInterleave (MaybeT m) 
Instance details

Defined in Control.Monad.Random.Class

Methods

interleave :: MaybeT m a -> MaybeT m a #

MonadRandom m => MonadRandom (MaybeT m) 
Instance details

Defined in Control.Monad.Random.Class

Methods

getRandomR :: Random a => (a, a) -> MaybeT m a #

getRandom :: Random a => MaybeT m a #

getRandomRs :: Random a => (a, a) -> MaybeT m [a] #

getRandoms :: Random a => MaybeT m [a] #

Monad m => MonadFail (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

fail :: String -> MaybeT m a #

MonadFix m => MonadFix (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

MonadIO m => MonadIO (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftIO :: IO a -> MaybeT m a #

MonadZip m => MonadZip (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

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

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

Foldable f => Foldable (MaybeT f) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

fold :: Monoid m => MaybeT f m -> m #

foldMap :: Monoid m => (a -> m) -> MaybeT f a -> m #

foldMap' :: Monoid m => (a -> m) -> MaybeT f a -> m #

foldr :: (a -> b -> b) -> b -> MaybeT f a -> b #

foldr' :: (a -> b -> b) -> b -> MaybeT f a -> b #

foldl :: (b -> a -> b) -> b -> MaybeT f a -> b #

foldl' :: (b -> a -> b) -> b -> MaybeT f a -> b #

foldr1 :: (a -> a -> a) -> MaybeT f a -> a #

foldl1 :: (a -> a -> a) -> MaybeT f a -> a #

toList :: MaybeT f a -> [a] #

null :: MaybeT f a -> Bool #

length :: MaybeT f a -> Int #

elem :: Eq a => a -> MaybeT f a -> Bool #

maximum :: Ord a => MaybeT f a -> a #

minimum :: Ord a => MaybeT f a -> a #

sum :: Num a => MaybeT f a -> a #

product :: Num a => MaybeT f a -> a #

Eq1 m => Eq1 (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftEq :: (a -> b -> Bool) -> MaybeT m a -> MaybeT m b -> Bool #

Ord1 m => Ord1 (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftCompare :: (a -> b -> Ordering) -> MaybeT m a -> MaybeT m b -> Ordering #

Read1 m => Read1 (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (MaybeT m a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [MaybeT m a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (MaybeT m a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [MaybeT m a] #

Show1 m => Show1 (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> MaybeT m a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [MaybeT m a] -> ShowS #

Contravariant m => Contravariant (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

contramap :: (a' -> a) -> MaybeT m a -> MaybeT m a' #

(>$) :: b -> MaybeT m b -> MaybeT m a #

Traversable f => Traversable (MaybeT f) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

sequenceA :: Applicative f0 => MaybeT f (f0 a) -> f0 (MaybeT f a) #

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

sequence :: Monad m => MaybeT f (m a) -> m (MaybeT f a) #

(Functor m, Monad m) => Alternative (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

empty :: MaybeT m a #

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

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

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

(Functor m, Monad m) => Applicative (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

pure :: a -> MaybeT m a #

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

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

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

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

Functor m => Functor (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

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

Monad m => Monad (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

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

return :: a -> MaybeT m a #

Monad m => MonadPlus (MaybeT m) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

mzero :: MaybeT m a #

mplus :: MaybeT m a -> MaybeT m a -> MaybeT m a #

PrimMonad m => PrimMonad (MaybeT m) 
Instance details

Defined in Control.Monad.Primitive

Associated Types

type PrimState (MaybeT m) #

Methods

primitive :: (State# (PrimState (MaybeT m)) -> (# State# (PrimState (MaybeT m)), a #)) -> MaybeT m a #

Monad m => Selective (MaybeT m) 
Instance details

Defined in Control.Selective

Methods

select :: MaybeT m (Either a b) -> MaybeT m (a -> b) -> MaybeT m b #

Generic (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

Associated Types

type Rep (MaybeT m a) :: Type -> Type #

Methods

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

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

(Read1 m, Read a) => Read (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

(Show1 m, Show a) => Show (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

show :: MaybeT m a -> String #

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

(Eq1 m, Eq a) => Eq (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

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

(Ord1 m, Ord a) => Ord (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

Methods

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

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

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

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

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

max :: MaybeT m a -> MaybeT m a -> MaybeT m a #

min :: MaybeT m a -> MaybeT m a -> MaybeT m a #

type Rep1 (MaybeT m :: Type -> Type) 
Instance details

Defined in Control.Monad.Trans.Maybe

type Rep1 (MaybeT m :: Type -> Type) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.0" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (m :.: Rec1 Maybe)))
type PrimState (MaybeT m) 
Instance details

Defined in Control.Monad.Primitive

type Rep (MaybeT m a) 
Instance details

Defined in Control.Monad.Trans.Maybe

type Rep (MaybeT m a) = D1 ('MetaData "MaybeT" "Control.Monad.Trans.Maybe" "transformers-0.6.1.0" 'True) (C1 ('MetaCons "MaybeT" 'PrefixI 'True) (S1 ('MetaSel ('Just "runMaybeT") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (m (Maybe a)))))

mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b #

Transform the computation inside a MaybeT.

hoistMaybe :: forall (m :: Type -> Type) b. Applicative m => Maybe b -> MaybeT m b #

Convert a Maybe computation to MaybeT.

maybeToExceptT :: forall (m :: Type -> Type) e a. Functor m => e -> MaybeT m a -> ExceptT e m a #

Convert a MaybeT computation to ExceptT, with a default exception value.

exceptToMaybeT :: forall (m :: Type -> Type) e a. Functor m => ExceptT e m a -> MaybeT m a #

Convert a ExceptT computation to MaybeT, discarding the value of any exception.

maybeToExceptS :: (Functor m, Monad m) => Automaton (MaybeT m) a b -> Automaton (ExceptT () m) a b Source #

Converts an Automaton in MaybeT to an Automaton in ExceptT.

Whenever Nothing is thrown, throw () instead.