lib: Replace some fromIntegral with toInteger.
This commit is contained in:
		
							parent
							
								
									b5ed2067d9
								
							
						
					
					
						commit
						ca2e55c954
					
				| @ -435,7 +435,7 @@ applyDigitGroupStyle (Just (DigitGroups c gs)) s = addseps (repeatLast gs) s | |||||||
|   where |   where | ||||||
|     addseps [] s = s |     addseps [] s = s | ||||||
|     addseps (g:gs) s |     addseps (g:gs) s | ||||||
|       | genericLength s <= toInteger g = s |       | toInteger (length s) <= toInteger g = s | ||||||
|       | otherwise     = let (part,rest) = genericSplitAt g s |       | otherwise     = let (part,rest) = genericSplitAt g s | ||||||
|                         in part ++ c : addseps gs rest |                         in part ++ c : addseps gs rest | ||||||
|     repeatLast [] = [] |     repeatLast [] = [] | ||||||
| @ -602,7 +602,7 @@ multiplyMixedAmountAndPrice n = mapMixedAmount (multiplyAmountAndPrice n) | |||||||
| -- | Calculate the average of some mixed amounts. | -- | Calculate the average of some mixed amounts. | ||||||
| averageMixedAmounts :: [MixedAmount] -> MixedAmount | averageMixedAmounts :: [MixedAmount] -> MixedAmount | ||||||
| averageMixedAmounts [] = 0 | averageMixedAmounts [] = 0 | ||||||
| averageMixedAmounts as = genericLength as `divideMixedAmount` sum as | averageMixedAmounts as = fromIntegral (length as) `divideMixedAmount` sum as | ||||||
| 
 | 
 | ||||||
| -- | Is this mixed amount negative, if we can tell that unambiguously? | -- | Is this mixed amount negative, if we can tell that unambiguously? | ||||||
| -- Ie when normalised, are all individual commodity amounts negative ? | -- Ie when normalised, are all individual commodity amounts negative ? | ||||||
|  | |||||||
| @ -560,8 +560,8 @@ nthdayofyearcontaining m md date | |||||||
|   | not (validDay   md) = error' $ "nthdayofyearcontaining: invalid day "  ++show md |   | not (validDay   md) = error' $ "nthdayofyearcontaining: invalid day "  ++show md | ||||||
|   | mmddOfSameYear <= date = mmddOfSameYear |   | mmddOfSameYear <= date = mmddOfSameYear | ||||||
|   | otherwise = mmddOfPrevYear |   | otherwise = mmddOfPrevYear | ||||||
|   where mmddOfSameYear = addDays (fromIntegral md-1) $ applyN (m-1) nextmonth s |   where mmddOfSameYear = addDays (toInteger md-1) $ applyN (m-1) nextmonth s | ||||||
|         mmddOfPrevYear = addDays (fromIntegral md-1) $ applyN (m-1) nextmonth $ prevyear s |         mmddOfPrevYear = addDays (toInteger md-1) $ applyN (m-1) nextmonth $ prevyear s | ||||||
|         s = startofyear date |         s = startofyear date | ||||||
| 
 | 
 | ||||||
| -- | For given date d find month-long interval that starts on nth day of month | -- | For given date d find month-long interval that starts on nth day of month | ||||||
| @ -612,8 +612,8 @@ nthdayofmonthcontaining md date | |||||||
| nthdayofweekcontaining :: WeekDay -> Day -> Day | nthdayofweekcontaining :: WeekDay -> Day -> Day | ||||||
| nthdayofweekcontaining n d | nthOfSameWeek <= d = nthOfSameWeek | nthdayofweekcontaining n d | nthOfSameWeek <= d = nthOfSameWeek | ||||||
|                            | otherwise = nthOfPrevWeek |                            | otherwise = nthOfPrevWeek | ||||||
|     where nthOfSameWeek = addDays (fromIntegral n-1) s |     where nthOfSameWeek = addDays (toInteger n-1) s | ||||||
|           nthOfPrevWeek = addDays (fromIntegral n-1) $ prevweek s |           nthOfPrevWeek = addDays (toInteger n-1) $ prevweek s | ||||||
|           s = startofweek d |           s = startofweek d | ||||||
| 
 | 
 | ||||||
| -- | For given date d find month-long interval that starts on nth weekday of month | -- | For given date d find month-long interval that starts on nth weekday of month | ||||||
| @ -647,9 +647,9 @@ advancetonthweekday n wd s = | |||||||
|   maybe err (addWeeks (n-1)) $ firstMatch (>=s) $ iterate (addWeeks 1) $ firstweekday s |   maybe err (addWeeks (n-1)) $ firstMatch (>=s) $ iterate (addWeeks 1) $ firstweekday s | ||||||
|   where |   where | ||||||
|     err = error' "advancetonthweekday: should not happen" |     err = error' "advancetonthweekday: should not happen" | ||||||
|     addWeeks k = addDays (7 * fromIntegral k) |     addWeeks k = addDays (7 * toInteger k) | ||||||
|     firstMatch p = headMay . dropWhile (not . p) |     firstMatch p = headMay . dropWhile (not . p) | ||||||
|     firstweekday = addDays (fromIntegral wd-1) . startofweek |     firstweekday = addDays (toInteger wd-1) . startofweek | ||||||
| 
 | 
 | ||||||
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------- | ||||||
| -- parsing | -- parsing | ||||||
|  | |||||||
| @ -716,7 +716,7 @@ journalBalanceTransactions assrt j' = | |||||||
|     runST $ do |     runST $ do | ||||||
|       -- We'll update a mutable array of transactions as we balance them, |       -- We'll update a mutable array of transactions as we balance them, | ||||||
|       -- not strictly necessary but avoids a sort at the end I think. |       -- not strictly necessary but avoids a sort at the end I think. | ||||||
|       balancedtxns <- newListArray (1, genericLength ts) ts |       balancedtxns <- newListArray (1, toInteger $ length ts) ts | ||||||
| 
 | 
 | ||||||
|       -- Infer missing posting amounts, check transactions are balanced, |       -- Infer missing posting amounts, check transactions are balanced, | ||||||
|       -- and check balance assertions. This is done in two passes: |       -- and check balance assertions. This is done in two passes: | ||||||
|  | |||||||
| @ -295,7 +295,7 @@ periodShrink today (YearPeriod y) | |||||||
| periodShrink today _ = YearPeriod y | periodShrink today _ = YearPeriod y | ||||||
|   where (y,_,_) = toGregorian today |   where (y,_,_) = toGregorian today | ||||||
| 
 | 
 | ||||||
| mondayBefore d = addDays (fromIntegral (1 - wd)) d | mondayBefore d = addDays (1 - toInteger wd) d | ||||||
|   where |   where | ||||||
|     (_,_,wd) = toWeekDate d |     (_,_,wd) = toWeekDate d | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1024,7 +1024,7 @@ data DigitGrp = DigitGrp { | |||||||
| instance Show DigitGrp where | instance Show DigitGrp where | ||||||
|   show (DigitGrp len num) = "\"" ++ padding ++ numStr ++ "\"" |   show (DigitGrp len num) = "\"" ++ padding ++ numStr ++ "\"" | ||||||
|     where numStr = show num |     where numStr = show num | ||||||
|           padding = genericReplicate (toInteger len - genericLength numStr) '0' |           padding = genericReplicate (toInteger len - toInteger (length numStr)) '0' | ||||||
| 
 | 
 | ||||||
| instance Sem.Semigroup DigitGrp where | instance Sem.Semigroup DigitGrp where | ||||||
|   DigitGrp l1 n1 <> DigitGrp l2 n2 = DigitGrp (l1 + l2) (n1 * 10^l2 + n2) |   DigitGrp l1 n1 <> DigitGrp l2 n2 = DigitGrp (l1 + l2) (n1 * 10^l2 + n2) | ||||||
|  | |||||||
| @ -779,7 +779,7 @@ tests_JournalReader = tests "JournalReader" [ | |||||||
|      bad "2011/1/1 00:00:60" |      bad "2011/1/1 00:00:60" | ||||||
|      bad "2011/1/1 3:5:7" |      bad "2011/1/1 3:5:7" | ||||||
|      -- timezone is parsed but ignored |      -- timezone is parsed but ignored | ||||||
|      let t = LocalTime (fromGregorian 2018 1 1) (TimeOfDay 0 0 (fromIntegral 0)) |      let t = LocalTime (fromGregorian 2018 1 1) (TimeOfDay 0 0 0) | ||||||
|      assertParseEq datetimep "2018/1/1 00:00-0800" t |      assertParseEq datetimep "2018/1/1 00:00-0800" t | ||||||
|      assertParseEq datetimep "2018/1/1 00:00+1234" t |      assertParseEq datetimep "2018/1/1 00:00+1234" t | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -240,7 +240,7 @@ dotquantityp :: JournalParser m Quantity | |||||||
| dotquantityp = do | dotquantityp = do | ||||||
|   -- lift $ traceparse "dotquantityp" |   -- lift $ traceparse "dotquantityp" | ||||||
|   dots <- filter (not.isSpace) <$> many (oneOf (". " :: [Char])) |   dots <- filter (not.isSpace) <$> many (oneOf (". " :: [Char])) | ||||||
|   return $ (/4) $ fromIntegral $ length dots |   return $ fromIntegral (length dots) / 4 | ||||||
| 
 | 
 | ||||||
| -- | XXX new comment line parser, move to Hledger.Read.Common.emptyorcommentlinep | -- | XXX new comment line parser, move to Hledger.Read.Common.emptyorcommentlinep | ||||||
| -- Parse empty lines, all-blank lines, and lines beginning with any of the provided | -- Parse empty lines, all-blank lines, and lines beginning with any of the provided | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user