streamt-0.5.0.0: Simple, Fair and Terminating Backtracking Monad Transformer
CopyrightOleg Kiselyov Sebastian Fischer David A Roberts
LicenseBSD3
MaintainerDavid A Roberts <d@vidr.cc>
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Stream

Description

This Haskell library provides an implementation of the MonadPlus type class that enumerates results of a non-deterministic computation by interleaving subcomputations in a way that has usually much better memory performance than other strategies with the same termination properties.

By using supensions in strategic positions, the user can ensure that the search does not diverge if there are remaining non-deterministic results.

More information is available on the author's website: http://okmij.org/ftp/Computation/monads.html#fair-bt-stream

Warning: Stream is only a monad when the results of observeAll are interpreted as a multiset, i.e., a valid transformation according to the monad laws may change the order of the results.

Synopsis

Documentation

data StreamT m a Source #

Results of non-deterministic computations of type StreamT m a can be enumerated efficiently.

Instances

Instances details
MonadTrans StreamT Source # 
Instance details

Defined in Control.Monad.Stream

Methods

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

MonadState s m => MonadState s (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

get :: StreamT m s #

put :: s -> StreamT m () #

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

MonadReader r m => MonadReader r (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

ask :: StreamT m r #

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

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

Monad m => Monad (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

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

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

return :: a -> StreamT m a #

Monad m => Functor (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

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

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

Monad m => MonadFail (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

fail :: String -> StreamT m a #

Monad m => Applicative (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

pure :: a -> StreamT m a #

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

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

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

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

(Monad m, Foldable m) => Foldable (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

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

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

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

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

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

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

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

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

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

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

null :: StreamT m a -> Bool #

length :: StreamT m a -> Int #

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

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

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

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

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

(Monad m, Traversable m) => Traversable (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

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

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

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

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

MonadIO m => MonadIO (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

liftIO :: IO a -> StreamT m a #

Monad m => Alternative (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

empty :: StreamT m a #

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

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

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

Monad m => MonadPlus (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

mzero :: StreamT m a #

mplus :: StreamT m a -> StreamT m a -> StreamT m a #

Monad m => MonadLogic (StreamT m) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

msplit :: StreamT m a -> StreamT m (Maybe (a, StreamT m a)) #

interleave :: StreamT m a -> StreamT m a -> StreamT m a #

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

ifte :: StreamT m a -> (a -> StreamT m b) -> StreamT m b -> StreamT m b #

once :: StreamT m a -> StreamT m a #

lnot :: StreamT m a -> StreamT m () #

Monad m => Semigroup (StreamT m a) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

(<>) :: StreamT m a -> StreamT m a -> StreamT m a #

sconcat :: NonEmpty (StreamT m a) -> StreamT m a #

stimes :: Integral b => b -> StreamT m a -> StreamT m a #

Monad m => Monoid (StreamT m a) Source # 
Instance details

Defined in Control.Monad.Stream

Methods

mempty :: StreamT m a #

mappend :: StreamT m a -> StreamT m a -> StreamT m a #

mconcat :: [StreamT m a] -> StreamT m a #

suspended :: Monad m => StreamT m a -> StreamT m a Source #

Suspensions can be used to ensure fairness.

runStream :: Stream a -> [a] Source #

Deprecated: use observeAll

The function runStream enumerates the results of a non-deterministic computation.

observeT :: MonadFail m => StreamT m a -> m a Source #

observeAllT :: Monad m => StreamT m a -> m [a] Source #

observeMany :: Int -> Stream a -> [a] Source #

observeManyT :: Monad m => Int -> StreamT m a -> m [a] Source #