fused-effects-random-1.1.0.0: Random number generation for fused-effects.

Control.Effect.Random

Description

Random variables in uniform and exponential distributions, with interleaving.

Since: 1.0

Synopsis

# Random effect

data Random m k where Source #

Uniformly-distributed random variables, with interleaving.

Since: 1.0

Constructors

 Uniform :: Random a => Random m a UniformR :: Random a => (a, a) -> Random m a Interleave :: m a -> Random m a

#### Instances

Instances details
 (Algebra sig m, RandomGen g) => Algebra (Random :+: sig) (RandomC g m) Source # Instance detailsDefined in Control.Carrier.Random.Gen Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RandomC g m) -> (Random :+: sig) n a -> ctx () -> RandomC g m (ctx a) #

uniform :: (Random a, Has Random sig m) => m a Source #

Produce a random variable uniformly distributed in a range determined by its type’s Random instance. For example:

• bounded types (instances of Bounded, such as Char) typically sample all of the constructors.
• fractional types, the range is normally the semi-closed interval [0,1).
• for Integer, the range is (arbitrarily) the range of Int.

Since: 1.1

uniformR :: (Random a, Has Random sig m) => (a, a) -> m a Source #

Produce a random variable uniformly distributed in the given range.

inRange (a, b) <$> uniformR (a, b) = pure True  Since: 1.1 interleave :: Has Random sig m => m a -> m a Source # Run a computation by splitting the generator, using one half for the passed computation and the other for the continuation. interleave (pure a) = pure a  Since: 1.0 # Non-uniform distributions exponential :: (Random a, Floating a, Has Random sig m) => a -> m a Source # Produce a random variable in an expnoential distribution with the given scale. Since: 1.1 # Re-exports class Monad m => Algebra (sig :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) | m -> sig # The class of carriers (results) for algebras (effect handlers) over signatures (effects), whose actions are given by the alg method. Since: fused-effects-1.0.0.0 Minimal complete definition alg #### Instances Instances details  Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n [] -> NonDet n a -> ctx () -> [ctx a] # Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n Maybe -> Empty n a -> ctx () -> Maybe (ctx a) # Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n NonEmpty -> Choose n a -> ctx () -> NonEmpty (ctx a) # Algebra sig m => Algebra sig (IdentityT m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (IdentityT m) -> sig n a -> ctx () -> IdentityT m (ctx a) # Algebra sig m => Algebra sig (Ap m) This instance permits effectful actions to be lifted into the Ap monad given a monoidal return type, which can provide clarity when chaining calls to mappend.mappend <$> act1 <*> (mappend <\$> act2 <*> act3)is equivalent togetAp (act1 <> act2 <> act3)Since: fused-effects-1.0.1.0 Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Ap m) -> sig n a -> ctx () -> Ap m (ctx a) # Algebra sig m => Algebra sig (Alt m) This instance permits effectful actions to be lifted into the Alt monad, which eases the invocation of repeated alternation with <|>:a <|> b <|> c <|> dis equivalent togetAlt (mconcat [a, b, c, d])Since: fused-effects-1.0.1.0 Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Alt m) -> sig n a -> ctx () -> Alt m (ctx a) # Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n IO -> Lift IO n a -> ctx () -> IO (ctx a) # Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n Identity -> Lift Identity n a -> ctx () -> Identity (ctx a) # Monoid w => Algebra (Writer w) ((,) w) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n ((,) w) -> Writer w n a -> ctx () -> (w, ctx a) # Algebra (Error e) (Either e) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Either e) -> Error e n a -> ctx () -> Either e (ctx a) # Algebra (Reader r) ((->) r :: Type -> Type) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n ((->) r) -> Reader r n a -> ctx () -> r -> ctx a # Algebra sig m => Algebra (Empty :+: sig) (MaybeT m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (MaybeT m) -> (Empty :+: sig) n a -> ctx () -> MaybeT m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (WriterT w m) -> (Writer w :+: sig) n a -> ctx () -> WriterT w m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (WriterT w m) -> (Writer w :+: sig) n a -> ctx () -> WriterT w m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (WriterT w m) -> (Writer w :+: sig) n a -> ctx () -> WriterT w m (ctx a) # Algebra sig m => Algebra (Error e :+: sig) (ExceptT e m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ExceptT e m) -> (Error e :+: sig) n a -> ctx () -> ExceptT e m (ctx a) # Algebra sig m => Algebra (State s :+: sig) (StateT s m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (StateT s m) -> (State s :+: sig) n a -> ctx () -> StateT s m (ctx a) # Algebra sig m => Algebra (State s :+: sig) (StateT s m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (StateT s m) -> (State s :+: sig) n a -> ctx () -> StateT s m (ctx a) # Algebra sig m => Algebra (State s :+: sig) (StateC s m) Instance detailsDefined in Control.Carrier.State.Church Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (StateC s m) -> (State s :+: sig) n a -> ctx () -> StateC s m (ctx a) # Algebra sig m => Algebra (Reader r :+: sig) (ReaderT r m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ReaderT r m) -> (Reader r :+: sig) n a -> ctx () -> ReaderT r m (ctx a) # (Algebra sig m, RandomGen g) => Algebra (Random :+: sig) (RandomC g m) Source # Instance detailsDefined in Control.Carrier.Random.Gen Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RandomC g m) -> (Random :+: sig) n a -> ctx () -> RandomC g m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RWST r w s m) -> (Reader r :+: (Writer w :+: (State s :+: sig))) n a -> ctx () -> RWST r w s m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RWST r w s m) -> (Reader r :+: (Writer w :+: (State s :+: sig))) n a -> ctx () -> RWST r w s m (ctx a) # (Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) Instance detailsDefined in Control.Algebra Methodsalg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RWST r w s m) -> (Reader r :+: (Writer w :+: (State s :+: sig))) n a -> ctx () -> RWST r w s m (ctx a) #

type Has (eff :: (Type -> Type) -> Type -> Type) (sig :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) = (Members eff sig, Algebra sig m) #

m is a carrier for sig containing eff.

Note that if eff is a sum, it will be decomposed into multiple Member constraints. While this technically allows one to combine multiple unrelated effects into a single Has constraint, doing so has two significant drawbacks:

1. Due to a problem with recursive type families, this can lead to significantly slower compiles.
2. It defeats ghc’s warnings for redundant constraints, and thus can lead to a proliferation of redundant constraints as code is changed.

Since: fused-effects-1.0.0.0

run :: Identity a -> a #

Run an action exhausted of effects to produce its final result value.

Since: fused-effects-1.0.0.0