Safe Haskell | Safe |
---|---|
Language | GHC2021 |
LambdaUC.Syntax.PrAlgo
Synopsis
- newtype PrAlgo a = PrAlgo {
- runAlgo :: Free AlgoActions a
- class Monad m => MonadRand (m :: Type -> Type) where
- data AlgoActions (a :: Type) where
- RandAction :: (Bool -> a) -> AlgoActions a
- class UniformDist s where
- uniformDist :: forall m. MonadRand m => m s
- rangeDist :: MonadRand m => Integer -> Integer -> m Integer
- pr :: PrAlgo Bool -> Rational
- withRandomBits :: [Bool] -> PrAlgo a -> Either (Bool -> PrAlgo a) a
- collectRandomBits :: PrAlgo a -> PrAlgo (a, [Bool])
- toMonadRand :: MonadRand m => PrAlgo a -> m a
- runIO :: PrAlgo a -> IO a
Syntax
This section defines the syntax of PrAlgo
monad for probabilistic algorithms.
Probabilistic algorithm. Allows only one action rand
to sample a random
bit.
Use with ExceptT
, MaybeT
or WriterT
if you want extra side-effects such
exceptions or writing debug messages.
Constructors
PrAlgo | |
Fields
|
class Monad m => MonadRand (m :: Type -> Type) where #
Class of monads that allow sampling a random bit.
Instances
MonadRand IO # | |
Defined in LambdaUC.Syntax.PrAlgo | |
MonadRand PrAlgo # | |
Defined in LambdaUC.Syntax.PrAlgo | |
(MonadTrans t, MonadRand m) => MonadRand (t m) # | |
Defined in LambdaUC.Syntax.PrAlgo | |
(XMonadTrans t, MonadRand m, bef ~ aft) => MonadRand (t m bef aft) # | |
Defined in LambdaUC.Syntax.PrAlgo | |
MonadRand (AsyncExT ex ports i i) # | |
Defined in LambdaUC.Syntax.Async |
data AlgoActions (a :: Type) where #
Constructors
RandAction :: (Bool -> a) -> AlgoActions a |
Instances
Functor AlgoActions # | |
Defined in LambdaUC.Syntax.PrAlgo Methods fmap :: (a -> b) -> AlgoActions a -> AlgoActions b # (<$) :: a -> AlgoActions b -> AlgoActions a # |
Distributions
Common probability distributions.
class UniformDist s where #
Instances
UniformDist Bool # | |
Defined in LambdaUC.Syntax.PrAlgo Methods uniformDist :: MonadRand m => m Bool # |
rangeDist :: MonadRand m => Integer -> Integer -> m Integer #
Sample a random value from the given range of Integer
Interpretations
Pure
withRandomBits :: [Bool] -> PrAlgo a -> Either (Bool -> PrAlgo a) a #
Run a probabilistic algorithm supplying the given stream of bits.
If the number of supplied bits was sufficient for all the rand
requests
that algorithm made until it terminated, evaluates to Right
of the
result. If the bits were exhausted before the algorithm was ready to
terminate, return Left
of the continuation with remaining computations.
collectRandomBits :: PrAlgo a -> PrAlgo (a, [Bool]) #
Run a probabilistic algorithm, collecting the random bits it samples.
This is, in some sense, dual to withRandomBits
: collected randomBits can
be fed back to an algorithm to repeat its execution.
Impure
toMonadRand :: MonadRand m => PrAlgo a -> m a #