fused-effects-random-1.1.0.1: Random number generation for fused-effects.
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Random

Description

Random variables in uniform and exponential distributions, with interleaving.

Since: 1.0

Synopsis

Random effect

data Random (m :: Type -> Type) k where Source #

Uniformly-distributed random variables, with interleaving.

Since: 1.0

Constructors

Uniform :: forall k (m :: Type -> Type). Random k => Random m k 
UniformR :: forall k (m :: Type -> Type). Random k => (k, k) -> Random m k 
Interleave :: forall (m :: Type -> Type) k. m k -> Random m k 

Instances

Instances details
(Algebra sig m, RandomGen g) => Algebra (Random :+: sig) (RandomC g m) Source # 
Instance details

Defined in Control.Carrier.Random.Gen

Methods

alg :: 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 :: forall a (sig :: (Type -> Type) -> Type -> Type) m. (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 :: forall a (sig :: (Type -> Type) -> Type -> Type) m. (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 :: forall (sig :: (Type -> Type) -> Type -> Type) m a. 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 :: forall a (sig :: (Type -> Type) -> Type -> Type) m. (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
Algebra Choose NonEmpty 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n NonEmpty -> Choose n a -> ctx () -> NonEmpty (ctx a) #

Algebra Empty Maybe 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n Maybe -> Empty n a -> ctx () -> Maybe (ctx a) #

Algebra NonDet [] 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n [] -> NonDet n a -> ctx () -> [ctx a] #

Algebra sig m => Algebra sig (Choosing m) 
Instance details

Defined in Control.Effect.Choose

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Choosing m) -> sig n a -> ctx () -> Choosing 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 to

getAp (act1 <> act2 <> act3)

Since: fused-effects-1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: 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 <|> d

is equivalent to

getAlt (mconcat [a, b, c, d])

Since: fused-effects-1.0.1.0

Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Alt m) -> sig n a -> ctx () -> Alt m (ctx a) #

Algebra sig m => Algebra sig (IdentityT m) 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (IdentityT m) -> sig n a -> ctx () -> IdentityT m (ctx a) #

Algebra (Lift Identity) Identity 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n Identity -> Lift Identity n a -> ctx () -> Identity (ctx a) #

Algebra (Lift IO) IO 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n IO -> Lift IO n a -> ctx () -> IO (ctx a) #

Algebra (Error e) (Either e) 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Either e) -> Error e n a -> ctx () -> Either e (ctx a) #

Monad m => Algebra (Lift m) (LiftC m) 
Instance details

Defined in Control.Carrier.Lift

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (LiftC m) -> Lift m n a -> ctx () -> LiftC m (ctx a) #

Monoid w => Algebra (Writer w) ((,) w) 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n ((,) w) -> Writer w n a -> ctx () -> (w, ctx a) #

Algebra (Reader r) ((->) r) 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n ((->) r) -> Reader r n a -> ctx () -> r -> ctx a #

Algebra sig m => Algebra (Choose :+: sig) (ChooseC m) 
Instance details

Defined in Control.Carrier.Choose.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ChooseC m) -> (Choose :+: sig) n a -> ctx () -> ChooseC m (ctx a) #

Algebra sig m => Algebra (Cull :+: (NonDet :+: sig)) (CullC m) 
Instance details

Defined in Control.Carrier.Cull.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (CullC m) -> (Cull :+: (NonDet :+: sig)) n a -> ctx () -> CullC m (ctx a) #

Algebra sig m => Algebra (Cut :+: (NonDet :+: sig)) (CutC m) 
Instance details

Defined in Control.Carrier.Cut.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (CutC m) -> (Cut :+: (NonDet :+: sig)) n a -> ctx () -> CutC m (ctx a) #

Algebra sig m => Algebra (Empty :+: sig) (EmptyC m) 
Instance details

Defined in Control.Carrier.Empty.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (EmptyC m) -> (Empty :+: sig) n a -> ctx () -> EmptyC m (ctx a) #

Algebra sig m => Algebra (Empty :+: sig) (EmptyC m) 
Instance details

Defined in Control.Carrier.Empty.Maybe

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (EmptyC m) -> (Empty :+: sig) n a -> ctx () -> EmptyC m (ctx a) #

Algebra sig m => Algebra (Empty :+: sig) (MaybeT m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 => Algebra (Fail :+: sig) (FailC m) 
Instance details

Defined in Control.Carrier.Fail.Either

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (FailC m) -> (Fail :+: sig) n a -> ctx () -> FailC m (ctx a) #

Algebra sig m => Algebra (Fresh :+: sig) (FreshC m) 
Instance details

Defined in Control.Carrier.Fresh.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (FreshC m) -> (Fresh :+: sig) n a -> ctx () -> FreshC m (ctx a) #

Algebra sig m => Algebra (Fresh :+: sig) (FreshC m) 
Instance details

Defined in Control.Carrier.Fresh.Strict

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (FreshC m) -> (Fresh :+: sig) n a -> ctx () -> FreshC m (ctx a) #

Algebra sig m => Algebra (NonDet :+: sig) (NonDetC m) 
Instance details

Defined in Control.Carrier.NonDet.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (NonDetC m) -> (NonDet :+: sig) n a -> ctx () -> NonDetC m (ctx a) #

Algebra sig m => Algebra (Trace :+: sig) (TraceC m) 
Instance details

Defined in Control.Carrier.Trace.Ignoring

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (TraceC m) -> (Trace :+: sig) n a -> ctx () -> TraceC m (ctx a) #

(MonadIO m, Algebra sig m) => Algebra (Trace :+: sig) (TraceC m) 
Instance details

Defined in Control.Carrier.Trace.Printing

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (TraceC m) -> (Trace :+: sig) n a -> ctx () -> TraceC m (ctx a) #

Algebra sig m => Algebra (Trace :+: sig) (TraceC m) 
Instance details

Defined in Control.Carrier.Trace.Returning

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (TraceC m) -> (Trace :+: sig) n a -> ctx () -> TraceC m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Accum w :+: sig) (AccumC w m) 
Instance details

Defined in Control.Carrier.Accum.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (AccumC w m) -> (Accum w :+: sig) n a -> ctx () -> AccumC w m (ctx a) #

(Algebra sig m, Semigroup w, MonadIO m) => Algebra (Accum w :+: sig) (AccumC w m) 
Instance details

Defined in Control.Carrier.Accum.IORef

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (AccumC w m) -> (Accum w :+: sig) n a -> ctx () -> AccumC w m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Accum w :+: sig) (AccumC w m) 
Instance details

Defined in Control.Carrier.Accum.Strict

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (AccumC w m) -> (Accum w :+: sig) n a -> ctx () -> AccumC w m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Accum w :+: sig) (AccumT w m) 
Instance details

Defined in Control.Algebra

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (AccumT w m) -> (Accum w :+: sig) n a -> ctx () -> AccumT w m (ctx a) #

Algebra sig m => Algebra (Error e :+: sig) (ErrorC e m) 
Instance details

Defined in Control.Carrier.Error.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ErrorC e m) -> (Error e :+: sig) n a -> ctx () -> ErrorC e m (ctx a) #

Algebra sig m => Algebra (Error e :+: sig) (ErrorC e m) 
Instance details

Defined in Control.Carrier.Error.Either

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ErrorC e m) -> (Error e :+: sig) n a -> ctx () -> ErrorC e m (ctx a) #

Algebra sig m => Algebra (Error e :+: sig) (ExceptT e m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 (Reader r :+: sig) (ReaderC r m) 
Instance details

Defined in Control.Carrier.Reader

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ReaderC r m) -> (Reader r :+: sig) n a -> ctx () -> ReaderC r m (ctx a) #

Algebra sig m => Algebra (Reader r :+: sig) (ReaderT r m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 => Algebra (State s :+: sig) (StateC s m) 
Instance details

Defined in Control.Carrier.State.Church

Methods

alg :: 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) #

(MonadIO m, Algebra sig m) => Algebra (State s :+: sig) (StateC s m) 
Instance details

Defined in Control.Carrier.State.IORef

Methods

alg :: 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 (State s :+: sig) (StateC s m) 
Instance details

Defined in Control.Carrier.State.Lazy

Methods

alg :: 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 (State s :+: sig) (StateC s m) 
Instance details

Defined in Control.Carrier.State.Strict

Methods

alg :: 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 (State s :+: sig) (StateT s m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 details

Defined in Control.Algebra

Methods

alg :: 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 (Throw e :+: sig) (ThrowC e m) 
Instance details

Defined in Control.Carrier.Throw.Either

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (ThrowC e m) -> (Throw e :+: sig) n a -> ctx () -> ThrowC e m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterC w m) 
Instance details

Defined in Control.Carrier.Writer.Church

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (WriterC w m) -> (Writer w :+: sig) n a -> ctx () -> WriterC w m (ctx a) #

(Monoid w, Algebra sig m) => Algebra (Writer w :+: sig) (WriterC w m) 
Instance details

Defined in Control.Carrier.Writer.Strict

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (WriterC w m) -> (Writer w :+: sig) n a -> ctx () -> WriterC w m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Writer w :+: sig) (WriterT w m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 details

Defined in Control.Algebra

Methods

alg :: 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 details

Defined in Control.Algebra

Methods

alg :: 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, RandomGen g) => Algebra (Random :+: sig) (RandomC g m) Source # 
Instance details

Defined in Control.Carrier.Random.Gen

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (RandomC g m) -> (Random :+: sig) n a -> ctx () -> RandomC g m (ctx a) #

(Reifies s (Interpreter eff m), Algebra sig m) => Algebra (eff :+: sig) (InterpretC s eff m) 
Instance details

Defined in Control.Carrier.Interpret

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (InterpretC s eff m) -> (eff :+: sig) n a -> ctx () -> InterpretC s eff m (ctx a) #

Algebra (eff :+: sig) (sub m) => Algebra (Labelled label eff :+: sig) (Labelled label sub m) 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (Labelled label sub m) -> (Labelled label eff :+: sig) n a -> ctx () -> Labelled label sub m (ctx a) #

(Algebra sig m, Monoid w) => Algebra (Reader r :+: (Writer w :+: (State s :+: sig))) (RWST r w s m) 
Instance details

Defined in Control.Algebra

Methods

alg :: 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 details

Defined in Control.Algebra

Methods

alg :: 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 details

Defined in Control.Algebra

Methods

alg :: 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) #

(LabelledMember label sub sig, Algebra sig m) => Algebra (sub :+: sig) (UnderLabel label sub m) 
Instance details

Defined in Control.Effect.Labelled

Methods

alg :: forall ctx (n :: Type -> Type) a. Functor ctx => Handler ctx n (UnderLabel label sub m) -> (sub :+: sig) n a -> ctx () -> UnderLabel label sub 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