Skip to content

Commit 3ec7a86

Browse files
committed
switch Doubles for Floats
1 parent 343af58 commit 3ec7a86

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

src/Distribution/Server/Features/PackageList.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ data PackageItem = PackageItem {
9292
-- Hotness: a more heuristic way to sort packages. presently non-existent.
9393
--itemHotness :: Int
9494
-- heuristic way to sort packages
95-
itemPackageRank :: !Double
95+
itemPackageRank :: !Float
9696
}
9797

9898
instance MemSize PackageItem where

src/Distribution/Server/Features/PackageRank.hs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,31 @@ import Data.Maybe ( isNothing )
3737
import Data.Ord ( comparing )
3838
import qualified Data.TarIndex as T
3939
import qualified Data.Time.Clock as CL
40-
import GHC.Float ( int2Double )
40+
import GHC.Float ( int2Float )
4141
import System.FilePath ( isExtensionOf )
4242
import qualified System.IO as SIO
4343

4444
data Scorer = Scorer
45-
{ maximum :: Double
46-
, score :: Double
45+
{ maximum :: Float
46+
, score :: Float
4747
}
4848
deriving Show
4949

5050
instance Semigroup Scorer where
5151
(Scorer a b) <> (Scorer c d) = Scorer (a + b) (c + d)
5252

53-
scorer :: Double -> Double -> Scorer
53+
scorer :: Float -> Float -> Scorer
5454
scorer maxim scr =
5555
if maxim >= scr then Scorer maxim scr else Scorer maxim maxim
5656

57-
fracScor :: Double -> Double -> Scorer
57+
fracScor :: Float -> Float -> Scorer
5858
fracScor maxim frac = scorer maxim (maxim * frac)
5959

60-
boolScor :: Double -> Bool -> Scorer
60+
boolScor :: Float -> Bool -> Scorer
6161
boolScor k True = Scorer k k
6262
boolScor k False = Scorer k 0
6363

64-
total :: Scorer -> Double
64+
total :: Scorer -> Float
6565
total (Scorer a b) = a / b
6666

6767
major :: Num a => [a] -> a
@@ -74,13 +74,13 @@ patches :: Num a => [a] -> a
7474
patches (_ : _ : xs) = sum xs
7575
patches _ = 0
7676

77-
numDays :: Maybe CL.UTCTime -> Maybe CL.UTCTime -> Double
77+
numDays :: Maybe CL.UTCTime -> Maybe CL.UTCTime -> Float
7878
numDays (Just first) (Just end) =
7979
fromRational $ toRational $ CL.diffUTCTime first end / fromRational
8080
(toRational CL.nominalDay)
8181
numDays _ _ = 0
8282

83-
freshness :: [Version] -> CL.UTCTime -> Bool -> IO Double
83+
freshness :: [Version] -> CL.UTCTime -> Bool -> IO Float
8484
freshness [] _ _ = return 0
8585
freshness (x : xs) lastUpd app =
8686
daysPastExpiration
@@ -89,7 +89,7 @@ freshness (x : xs) lastUpd app =
8989
versionLatest = versionNumbers x
9090
daysPastExpiration =
9191
age >>= (\a -> return $ max 0 a - expectedUpdateInterval)
92-
expectedUpdateInterval = int2Double
92+
expectedUpdateInterval = int2Float
9393
(min (versionStabilityInterval versionLatest) $ length (x : xs))
9494
versionStabilityInterval v | patches v > 3 && major v > 0 = 700
9595
| patches v > 3 = 450
@@ -145,13 +145,13 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
145145
index <- documentIndex
146146
path <- documentPath
147147
return $ liftM2 (,) path (join $ liftM2 T.lookup index path)
148-
documentLines :: IO Double
148+
documentLines :: IO Float
149149
documentLines = documentationEntr >>= filterLinesTar (const True)
150-
srcLines :: IO Double
150+
srcLines :: IO Float
151151
srcLines = packageEntr >>= filterLinesTar (isExtensionOf ".hs")
152152

153153
filterLinesTar
154-
:: (FilePath -> Bool) -> Maybe (FilePath, T.TarIndexEntry) -> IO Double
154+
:: (FilePath -> Bool) -> Maybe (FilePath, T.TarIndexEntry) -> IO Float
155155
filterLinesTar f (Just (path, T.TarFileEntry offset)) =
156156
if f path then getLines path offset else return 0
157157
filterLinesTar f (Just (_, T.TarDir dir)) =
@@ -166,7 +166,7 @@ rankIO vers recentDownloads maintainers docs env tarCache pkgs = do
166166
case Tar.read header of
167167
(Tar.Next Tar.Entry { Tar.entryContent = Tar.NormalFile _ siz } _) -> do
168168
body <- BSL.hGet handle (fromIntegral siz)
169-
return $ int2Double . length . BSL.split 10 $ body
169+
return $ int2Float . length . BSL.split 10 $ body
170170
_ -> return 0
171171

172172
documentPath = do
@@ -178,9 +178,9 @@ authorScore maintainers desc =
178178
boolScor 1 (not $ S.null $ author desc) <> maintScore
179179
where
180180
maintScore =
181-
boolScor 3 (maintainers > 1) <> scorer 5 (int2Double maintainers)
181+
boolScor 3 (maintainers > 1) <> scorer 5 (int2Float maintainers)
182182

183-
codeScore :: IO Double -> IO Double -> IO Scorer
183+
codeScore :: IO Float -> IO Float -> IO Scorer
184184
codeScore documentL haskellL = do
185185
docum <- documentL
186186
haskell <- haskellL
@@ -217,15 +217,15 @@ versionScore versionList versions lastUploads desc = do
217217
<> scorer 40 (numDays (safeHead lUps) (safeLast lUps))
218218
<> scorer
219219
15
220-
(int2Double $ length $ filter (\x -> major x > 0 || minor x > 0)
220+
(int2Float $ length $ filter (\x -> major x > 0 || minor x > 0)
221221
intUse
222222
)
223223
<> scorer
224224
20
225-
(int2Double $ 4 * length
225+
(int2Float $ 4 * length
226226
(filter (\x -> major x > 0 && patches x > 0) intUse)
227227
)
228-
<> scorer 10 (int2Double $ patches $ maximumBy (comparing patches) intUse)
228+
<> scorer 10 (int2Float $ patches $ maximumBy (comparing patches) intUse)
229229
<> boolScor 8 (any (\x -> major x == 0 && patches x > 0) intUse)
230230
<> boolScor 10 (any (\x -> major x > 0 && major x < 20) intUse)
231231
<> boolScor 5 (not $ null depre)
@@ -240,7 +240,7 @@ temporalScore p lastUploads versionList recentDownloads = do
240240
isApp = (isNothing . library) p && (not . null . executables) p
241241
downloadScore = calcDownScore recentDownloads
242242
calcDownScore i = Scorer 5 $ min
243-
( (logBase 2 (int2Double $ max 0 (i - 100) + 100) - 6.6)
243+
( (logBase 2 (int2Float $ max 0 (i - 100) + 100) - 6.6)
244244
/ (if isApp then 5 else 6)
245245
)
246246
5
@@ -251,14 +251,14 @@ temporalScore p lastUploads versionList recentDownloads = do
251251
-- Missing dependencyFreshnessScore for reasonable effectivity needs caching
252252
tractionScore = do
253253
fresh <- packageFreshness
254-
return $ boolScor 1 (fresh * int2Double recentDownloads > 1000)
254+
return $ boolScor 1 (fresh * int2Float recentDownloads > 1000)
255255

256256
rankPackagePage :: PackageDescription -> Scorer
257257
rankPackagePage p = tests <> benchs <> desc <> homeP <> sourceRp <> cats
258258
where
259259
tests = boolScor 50 (hasTests p)
260260
benchs = boolScor 10 (hasBenchmarks p)
261-
desc = Scorer 30 (min 1 (int2Double (S.length $ description p) / 300))
261+
desc = Scorer 30 (min 1 (int2Float (S.length $ description p) / 300))
262262
-- documentation = boolScor 30 ()
263263
homeP = boolScor 30 (not $ S.null $ homepage p)
264264
sourceRp = boolScor 8 (not $ null $ sourceRepos p)
@@ -274,7 +274,7 @@ rankPackage
274274
-> TarIndexCacheFeature
275275
-> ServerEnv
276276
-> [PkgInfo]
277-
-> IO Double
277+
-> IO Float
278278
rankPackage versions recentDownloads maintainers docs tarCache env pkgs =
279279
total
280280
. (<>) (rankPackagePage pkgD)

src/Distribution/Server/Framework/MemSize.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ instance MemSize Integer where
135135
instance MemSize Float where
136136
memSize _ = 2
137137

138-
instance MemSize Double where
139-
memSize _ = 3
140-
141138
instance MemSize UTCTime where
142139
memSize _ = 7
143140

0 commit comments

Comments
 (0)