3
0
Fork 0
forked from mirrors/nixpkgs

haskellPackages.misfortune: apply patch to fix GHC 9 build

This commit is contained in:
Naïm Favier 2022-03-20 09:55:59 +01:00
parent 6b25081893
commit f8c740b781
No known key found for this signature in database
GPG key ID: 49B07322580B7EE2
2 changed files with 76 additions and 0 deletions

View file

@ -2372,6 +2372,12 @@ 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);
# Ships a custom cabal-doctest Setup.hs in the release tarball, but the actual
# test suite is commented out, so the required dependency is missing naturally.
# We need to use a default Setup.hs instead. Current master doesn't exhibit

View file

@ -0,0 +1,70 @@
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))