polysemy-RandomFu 0.4.2.0 → 0.4.2.1
raw patch · 4 files changed
+53/−21 lines, 4 files
Files
- ChangeLog.md +3/−0
- Readme.md +6/−6
- polysemy-RandomFu.cabal +33/−6
- src/Polysemy/ConstraintAbsorber/MonadRandom.hs +11/−9
ChangeLog.md view
@@ -1,3 +1,6 @@+## v0.4.2.1+- Reordered template splice for ghc9+ ## v0.4.2.0 - Updated upper bounds for polysemy 1.5
Readme.md view
@@ -1,4 +1,4 @@-# polysemy-RandomFu v0.4.0.0+# polysemy-RandomFu v0.4.2.1 [![Build Status][travis-badge]][travis] [![Hackage][hackage-badge]][hackage]@@ -20,21 +20,21 @@ 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 +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-- See the tests (in https://github.com/adamConnerSax/Polysemy-Extra/blob/master/polysemy-RandomFu/test/RandomFuSpec.hs) +- See the tests (in https://github.com/adamConnerSax/Polysemy-Extra/blob/master/polysemy-RandomFu/test/RandomFuSpec.hs) for more details about how to use this effect [travis]: <https://travis-ci.org/adamConnerSax/polysemy-extra>
polysemy-RandomFu.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack ----- hash: 02459f2ca86576d164898f8679cc877c94a0e0a6a6d64a2bc9d9f6f97cc82adb+-- hash: 349bb25cc65abf6aff1ddd691ea89785dcab4cad79092dc05c66631746153a79 name: polysemy-RandomFu-version: 0.4.2.0+version: 0.4.2.1 synopsis: Experimental, RandomFu effect and interpreters for polysemy description: Please see the README on GitHub at <https://github.com/adamConnerSax/polysemy-Extra/tree/master/polysemy-RandomFu#polysemy-randomfu> category: Polysemy@@ -18,7 +18,8 @@ copyright: 2019 Adam Conner-Sax license: BSD3 license-file: LICENSE-tested-with: GHC ==8.6.4+tested-with:+ GHC ==8.6.4 build-type: Simple extra-source-files: Readme.md@@ -37,7 +38,20 @@ Paths_polysemy_RandomFu hs-source-dirs: src- default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax+ default-extensions:+ DataKinds+ DeriveFunctor+ FlexibleContexts+ GADTs+ LambdaCase+ PolyKinds+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TypeApplications+ TypeOperators+ TypeFamilies+ UnicodeSyntax ghc-options: -fplugin=Polysemy.Plugin build-depends: base >=4.7 && <5@@ -56,7 +70,20 @@ Paths_polysemy_RandomFu hs-source-dirs: test- default-extensions: DataKinds DeriveFunctor FlexibleContexts GADTs LambdaCase PolyKinds RankNTypes ScopedTypeVariables StandaloneDeriving TypeApplications TypeOperators TypeFamilies UnicodeSyntax+ default-extensions:+ DataKinds+ DeriveFunctor+ FlexibleContexts+ GADTs+ LambdaCase+ PolyKinds+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TypeApplications+ TypeOperators+ TypeFamilies+ UnicodeSyntax ghc-options: -fplugin=Polysemy.Plugin -threaded -rtsopts -with-rtsopts=-N build-tool-depends: hspec-discover:hspec-discover >=2.0
src/Polysemy/ConstraintAbsorber/MonadRandom.hs view
@@ -15,14 +15,6 @@ import qualified Data.Random.Internal.Source as R --------------------------------------------------------------------------------- | absorb a @MonadError e@ constraint into @Member (Error e) r => Sem r@-absorbMonadRandom :: Member RandomFu r- => (R.MonadRandom (Sem r) => Sem r a) -> Sem r a-absorbMonadRandom = absorbWithSem @R.MonadRandom @Action- (RandomDict getRandomPrim)- (Sub Dict) -{-# INLINEABLE absorbMonadRandom #-}- -- | A dictionary of the functions we need to supply -- to make an instance of MonadRandom data RandomDict m = RandomDict { getRandomPrim_ :: forall t. R.Prim t -> m t }@@ -36,7 +28,7 @@ deriving (Functor, Applicative, Monad) -- | Given a reifiable mtl Error dictionary,--- we can make an instance of @MonadError@ for the action+-- we can make an instance of @MonadRandom@ for the action -- wrapped in @Action@. $(R.monadRandom [d| instance ( Monad m@@ -46,3 +38,13 @@ $ getRandomPrim_ (reflect $ Proxy @s') t {-# INLINEABLE getRandomPrim #-} |])+++-- | absorb a @MonadError e@ constraint into @Member (Error e) r => Sem r@+absorbMonadRandom :: forall r a. (Member RandomFu r)+ => (R.MonadRandom (Sem r) => Sem r a)+ -> Sem r a+absorbMonadRandom = absorbWithSem @R.MonadRandom @Action+ (RandomDict (getRandomPrim @r))+ (Sub Dict)+{-# INLINEABLE absorbMonadRandom #-}