Safe Haskell | None |
---|---|

Language | Haskell2010 |

- class (Semiring w, Monad m) => MonadWeighted w m | m -> w where
- collect :: (Foldable m, MonadWeighted w m) => m a -> w
- toCovector :: (Foldable m, MonadWeighted w m) => m a -> (a -> w) -> w

# 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`

.

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

embeds a simple weighted action.`weighted`

(a,w)

is an action that produces the output `weight`

w`w`

.

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

is an action that executes the action `weigh`

m`m`

and adds
its output to the value of the computation.

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

is an action that executes the action `scale`

m`m`

, which
returns a value and a function, and returns the value, applying
the function to the output.

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

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

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

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

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

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

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

MonadWeighted w m => MonadWeighted w (ReaderT * r m) 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.