parent
3865a90172
commit
c996ce4415
@ -2348,12 +2348,6 @@ self: super: {
|
||||
# https://github.com/kuribas/mfsolve/issues/8
|
||||
mfsolve = dontCheck super.mfsolve;
|
||||
|
||||
# compatibility with random-fu 0.3 https://github.com/mokus0/misfortune/pull/5
|
||||
misfortune = appendPatch ./patches/misfortune-ghc9.patch (overrideCabal (drv: {
|
||||
revision = null;
|
||||
editedCabalFile = null;
|
||||
}) super.misfortune);
|
||||
|
||||
# GHC 9 support https://github.com/lambdabot/dice/pull/2
|
||||
dice = appendPatch (fetchpatch {
|
||||
name = "dice-ghc9.patch";
|
||||
|
@ -1,70 +0,0 @@
|
||||
diff --git a/misfortune.cabal b/misfortune.cabal
|
||||
index f5d0dd3..faa5794 100644
|
||||
--- a/misfortune.cabal
|
||||
+++ b/misfortune.cabal
|
||||
@@ -113,7 +113,8 @@ Library
|
||||
directory,
|
||||
filepath,
|
||||
knob,
|
||||
- random-fu >= 0.2.2,
|
||||
+ random,
|
||||
+ random-fu >= 0.3,
|
||||
semigroups,
|
||||
text,
|
||||
utf8-string,
|
||||
diff --git a/src/Data/Fortune.hs b/src/Data/Fortune.hs
|
||||
index 16d221e..ffbc970 100644
|
||||
--- a/src/Data/Fortune.hs
|
||||
+++ b/src/Data/Fortune.hs
|
||||
@@ -64,6 +64,7 @@ import Paths_misfortune
|
||||
import System.Directory
|
||||
import System.Environment
|
||||
import System.FilePath
|
||||
+import System.Random.Stateful (newIOGenM, newStdGen)
|
||||
|
||||
-- |The number of fortune strings in the index
|
||||
numFortunes :: S.FortuneStats -> Int
|
||||
@@ -233,9 +234,10 @@ randomFortune paths = withFortuneFiles '%' False paths $ \fs -> do
|
||||
-- random fortune from that file (unformly).
|
||||
randomFortuneFromRandomFile :: RVar FortuneFile -> IO String
|
||||
randomFortuneFromRandomFile file = do
|
||||
- f <- sample file
|
||||
+ gen <- newStdGen >>= newIOGenM
|
||||
+ f <- sampleFrom gen file
|
||||
n <- getNumFortunes f
|
||||
- i <- sample (uniform 0 (n-1))
|
||||
+ i <- sampleFrom gen (uniform 0 (n-1))
|
||||
T.unpack <$> getFortune f i
|
||||
|
||||
-- |Given a list of 'FortuneFile's, compute a distrubution over them weighted by the number
|
||||
diff --git a/src/Fortune.hs b/src/Fortune.hs
|
||||
index 5a27578..d6ffb74 100644
|
||||
--- a/src/Fortune.hs
|
||||
+++ b/src/Fortune.hs
|
||||
@@ -21,6 +21,7 @@ import System.Environment
|
||||
import System.Exit
|
||||
import System.FilePath
|
||||
import System.IO
|
||||
+import System.Random.Stateful (newIOGenM, newStdGen)
|
||||
import Text.Printf
|
||||
import Text.Regex.Base
|
||||
import Text.Regex.PCRE
|
||||
@@ -200,6 +201,7 @@ main = do
|
||||
fortunes <- filterM (filterFile args) (fortuneFiles args)
|
||||
|
||||
dist <- getDist args fortunes
|
||||
+ gen <- newStdGen >>= newIOGenM
|
||||
|
||||
when (numEvents dist == 0) $ do
|
||||
hPutStrLn stderr "No fortunes matched the filter criteria"
|
||||
@@ -225,8 +227,8 @@ main = do
|
||||
, let pctStr = printf "(%.2f%%)" (100 * weight / totalWeight dist) :: String
|
||||
]
|
||||
else do
|
||||
- (file, fortuneDist) <- sample dist
|
||||
- fortune <- sample fortuneDist
|
||||
+ (file, fortuneDist) <- sampleFrom gen dist
|
||||
+ fortune <- sampleFrom gen fortuneDist
|
||||
putStrLn . T.unpack =<< getFortune file fortune
|
||||
|
||||
getDist :: Args -> [FortuneFile] -> IO (Categorical Float (FortuneFile, Categorical Float Int))
|
Loading…
Reference in New Issue
Block a user