weighted-0.3.0.1: Writer monad which uses semiring constraint

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Weighted.Class

Synopsis

Documentation

class (Semiring w, Monad m) => MonadWeighted w m | m -> w where Source #

A class for computations which carry a weight with them. It is analogous to Writer over the Product Monoid.

Methods

weighted :: (a, w) -> m a Source #

weighted (a,w) embeds a simple weighted action.

weight :: w -> m () Source #

weight w is an action that produces the output w.

weigh :: m a -> m (a, w) Source #

weigh m is an action that executes the action m and adds its output to the value of the computation.

scale :: m (a, w -> w) -> m a Source #

scale m is an action that executes the action m, which returns a value and a function, and returns the value, applying the function to the output.

Instances

MonadWeighted w m => MonadWeighted w (MaybeT m) Source # 

Methods

weighted :: (a, w) -> MaybeT m a Source #

weight :: w -> MaybeT m () Source #

weigh :: MaybeT m a -> MaybeT m (a, w) Source #

scale :: MaybeT m (a, w -> w) -> MaybeT m a Source #

MonadWeighted w m => MonadWeighted w (StateT s m) Source # 

Methods

weighted :: (a, w) -> StateT s m a Source #

weight :: w -> StateT s m () Source #

weigh :: StateT s m a -> StateT s m (a, w) Source #

scale :: StateT s m (a, w -> w) -> StateT s m a Source #

MonadWeighted w m => MonadWeighted w (StateT s m) Source # 

Methods

weighted :: (a, w) -> StateT s m a Source #

weight :: w -> StateT s m () Source #

weigh :: StateT s m a -> StateT s m (a, w) Source #

scale :: StateT s m (a, w -> w) -> StateT s m a Source #

MonadWeighted w m => MonadWeighted w (IdentityT * m) Source # 

Methods

weighted :: (a, w) -> IdentityT * m a Source #

weight :: w -> IdentityT * m () Source #

weigh :: IdentityT * m a -> IdentityT * m (a, w) Source #

scale :: IdentityT * m (a, w -> w) -> IdentityT * m a Source #

MonadWeighted w m => MonadWeighted w (ExceptT e m) Source # 

Methods

weighted :: (a, w) -> ExceptT e m a Source #

weight :: w -> ExceptT e m () Source #

weigh :: ExceptT e m a -> ExceptT e m (a, w) Source #

scale :: ExceptT e m (a, w -> w) -> ExceptT e m a Source #

(DetectableZero w, Monad m, Alternative m) => MonadWeighted w (FilterT w m) Source # 

Methods

weighted :: (a, w) -> FilterT w m a Source #

weight :: w -> FilterT w m () Source #

weigh :: FilterT w m a -> FilterT w m (a, w) Source #

scale :: FilterT w m (a, w -> w) -> FilterT w m a Source #

(Semiring w, Monad m) => MonadWeighted w (WeightedT w m) Source # 

Methods

weighted :: (a, w) -> WeightedT w m a Source #

weight :: w -> WeightedT w m () Source #

weigh :: WeightedT w m a -> WeightedT w m (a, w) Source #

scale :: WeightedT w m (a, w -> w) -> WeightedT w m a Source #

MonadWeighted w m => MonadWeighted w (ReaderT * r m) Source # 

Methods

weighted :: (a, w) -> ReaderT * r m a Source #

weight :: w -> ReaderT * r m () Source #

weigh :: ReaderT * r m a -> ReaderT * r m (a, w) Source #

scale :: ReaderT * r m (a, w -> w) -> ReaderT * r m a Source #

collect :: (Foldable m, MonadWeighted w m) => m a -> w Source #

Collect the total weight of a computation.

toCovector :: (Foldable m, MonadWeighted w m) => m a -> (a -> w) -> w Source #

Transform a weighted computation to a covector.