urn-random-0.1.0.0: A package for updatable discrete distributions

Safe HaskellNone
LanguageHaskell2010

Data.Urn

Contents

Synopsis

Types

data Urn a Source #

Instances

Show a => Show (Urn a) Source #

This Show instance prints out the elements from most-weighted to least-weighted; however, do not rely on the order of equally-weighted elements, as this may depend on details of the implementation.

Methods

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

show :: Urn a -> String #

showList :: [Urn a] -> ShowS #

NFData a => NFData (Urn a) Source # 

Methods

rnf :: Urn a -> () #

class Monad m => MonadSample m Source #

Instances

MonadSample IO Source # 

Methods

randomWord :: (Word, Word) -> IO Word Source #

MonadSample Gen Source # 

Methods

randomWord :: (Word, Word) -> Gen Word Source #

MonadSample m => MonadSample (MaybeT m) Source # 

Methods

randomWord :: (Word, Word) -> MaybeT m Word Source #

(Monad m, RandomGen g) => MonadSample (RandT g m) Source # 

Methods

randomWord :: (Word, Word) -> RandT g m Word Source #

MonadSample m => MonadSample (ExceptT e m) Source # 

Methods

randomWord :: (Word, Word) -> ExceptT e m Word Source #

MonadSample m => MonadSample (StateT s m) Source # 

Methods

randomWord :: (Word, Word) -> StateT s m Word Source #

MonadSample m => MonadSample (StateT s m) Source # 

Methods

randomWord :: (Word, Word) -> StateT s m Word Source #

(MonadSample m, Monoid w) => MonadSample (WriterT w m) Source # 

Methods

randomWord :: (Word, Word) -> WriterT w m Word Source #

(MonadSample m, Monoid w) => MonadSample (WriterT w m) Source # 

Methods

randomWord :: (Word, Word) -> WriterT w m Word Source #

MonadSample m => MonadSample (IdentityT * m) Source # 
MonadSample m => MonadSample (ContT * r m) Source # 

Methods

randomWord :: (Word, Word) -> ContT * r m Word Source #

MonadSample m => MonadSample (ReaderT * r m) Source # 

Methods

randomWord :: (Word, Word) -> ReaderT * r m Word Source #

(MonadSample m, Monoid w) => MonadSample (RWST r w s m) Source # 

Methods

randomWord :: (Word, Word) -> RWST r w s m Word Source #

(MonadSample m, Monoid w) => MonadSample (RWST r w s m) Source # 

Methods

randomWord :: (Word, Word) -> RWST r w s m Word Source #

Construction

singleton :: Weight -> a -> Urn a Source #

fromList :: [(Weight, a)] -> Maybe (Urn a) Source #

Sampling

sample :: MonadSample m => Urn a -> m a Source #

sampleM :: MonadSample m => Urn (m a) -> m a Source #

remove :: MonadSample m => Urn a -> m (Weight, a, Maybe (Urn a)) Source #

removeM :: MonadSample m => Urn (m a) -> m (Weight, a, Maybe (Urn (m a))) Source #

Updating

insert :: Weight -> a -> Urn a -> Urn a Source #

update :: MonadSample m => (Weight -> a -> (Weight, a)) -> Urn a -> m (Weight, a, Weight, a, Urn a) Source #

replace :: MonadSample m => Weight -> a -> Urn a -> m (Weight, a, Urn a) Source #

Other functions

frequency :: MonadSample m => [(Weight, m a)] -> m a Source #

addToUrn :: Foldable t => Urn a -> t (Weight, a) -> Urn a Source #

Urn properties

size :: Urn a -> Word Source #