HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulerandom-fu-0.3.0.1Haskell2010

Data.Random.Sample

Synopsis
  • Packagerandom-fu-0.3.0.1
  • Exports4
  • LanguageHaskell2010
  • LicenceLicenseRef-PublicDomain
  • SourceSample.hs
classclass Sampleable (d :: Type -> Type) (m :: Type -> Type) t where

A typeclass allowing Distributions and RVars to be sampled. Both may also be sampled via runRVar or runRVarT, but I find it psychologically pleasing to be able to sample both using this function, as they are two separate abstractions for one base concept: a random variable.

Methods

  • sampleFrom :: StatefulGen g m => g -> d t -> m t

    Directly sample from a distribution or random variable, using the given source of entropy.

Instances2Sampleable
valuesampleState :: (Distribution d t, RandomGen g, MonadState g m) => d t -> m t

Sample a random variable in a "functional" style. Typical instantiations of s are System.Random.StdGen or System.Random.Mersenne.Pure64.PureMT. sample :: (Distribution d a, StatefulGen g m, MonadReader g m) => d t -> m t sample thing gen = runStateGen gen (stateGen -> sampleFrom stateGen thing)

valuesamplePure :: (Distribution d t, RandomGen g) => d t -> g -> (t, g)

Sample a random variable in a "functional" style. Typical instantiations of g are System.Random.StdGen or System.Random.Mersenne.Pure64.PureMT.