polysemy-RandomFu: Experimental, RandomFu effect and interpreters for polysemy

[ bsd3, library, polysemy ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.1.0, 0.4.2.0, 0.4.2.1, 0.4.3.0, 0.4.4.0, 0.4.4.1, 0.5.0.0
Change log ChangeLog.md
Dependencies base (>=4.7 && <5), mtl (>=2.0 && <2.3), polysemy (>=1.3 && <1.8), polysemy-plugin (>0.2.0 && <0.5), polysemy-zoo (>=0.6.0 && <0.9), random (>=1.2.1 && <1.3), random-fu (>=0.2.7.7 && <0.4.0.0), random-source (>=0.3.0.11 && <0.4.0.0), rvar (>=0.3.0 && <0.4) [details]
Tested with ghc ==8.6.4
License BSD-3-Clause
Copyright 2019 Adam Conner-Sax
Author Adam Conner-Sax
Maintainer adam_conner_sax@yahoo.com
Category Polysemy
Home page https://github.com/adamConnerSax/polysemy-Extra#readme
Bug tracker https://github.com/adamConnerSax/polysemy-Extra/issues
Source repo head: git clone https://github.com/adamConnerSax/polysemy-Extra(polysemy-RandomFu)
Uploaded by adamCS at 2022-04-26T00:44:47Z
Distributions
Downloads 2894 total (9 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-04-26 [all 1 reports]

Readme for polysemy-RandomFu-0.5.0.0

[back to package description]

polysemy-RandomFu v0.5.0.0

Build Status Hackage Hackage Dependencies

Summary

  • Polysemy effect and intepreters to use the random-fu library in a polysemy effect union (like an mtl stack).
  • Includes a constraint "absorber" (see https://github.com/isovector/polysemy-zoo/blob/master/src/Polysemy/ConstraintAbsorber.hs) for the random-fu MonadRandom typeclass.
  • NB: If you compile with random-fu >= 0.3.0.0, there is no longer a constraint absorber in this library since random-fu no longer uses random-source or MonadRandom.

Example (from the tests)

import           Polysemy
import           Polysemy.RandomFu

import qualified Data.Random                   as R
import qualified Data.Random.Source.PureMT     as R

getRandomInts :: Member RandomFu r => Int -> Sem r [Int]
getRandomInts nDraws =
  sampleRVar $ M.replicateM nDraws (R.uniform 0 (100 :: Int))

main :: IO ()
main = do
  seed <- R.newPureMT
  putStrLn . show $ runM . runRandomIOPureMT (R.pureMT seed) $ getRandomInts 5

should print a list of 5 pseudo-random integers. They will be different each time you run because the newPureMT function returns a different seed each time it's called. If you replace that seed in the R.pureMT argument to runRandomIOPureMT with a fixed number then you will get the same pseudo-random sequences each time. This can be useful for testing.

Notes