From 5b9c5459be5d1d0d33ac6dfe9a4d745daa060e01 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 14 Nov 2012 17:25:02 +0000 Subject: [PATCH] web: make hledger[-lib] compatible with all of yesod's language extensions Useful when building all of hledger-web at once. --- hledger-lib/Hledger/Data/Account.hs | 4 ++-- hledger-lib/Hledger/Data/Amount.hs | 10 ++++++---- hledger-lib/Hledger/Data/Commodity.hs | 2 +- hledger-lib/Hledger/Data/Dates.hs | 1 + hledger-lib/Hledger/Data/Transaction.hs | 2 +- hledger-lib/Hledger/Read/JournalReader.hs | 2 +- hledger-lib/Hledger/Utils.hs | 2 +- hledger/Hledger/Cli/Add.hs | 2 +- hledger/Hledger/Cli/Stats.hs | 4 ++-- hledger/Hledger/Cli/Version.hs | 2 +- 10 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hledger-lib/Hledger/Data/Account.hs b/hledger-lib/Hledger/Data/Account.hs index 9aee1913a..8cb56ea87 100644 --- a/hledger-lib/Hledger/Data/Account.hs +++ b/hledger-lib/Hledger/Data/Account.hs @@ -26,7 +26,7 @@ import Hledger.Utils instance Show Account where show Account{..} = printf "Account %s (boring:%s, ebalance:%s, ibalance:%s)" aname - (if aboring then "y" else "n") + (if aboring then "y" else "n" :: String) (showMixedAmount aebalance) (showMixedAmount aibalance) @@ -159,7 +159,7 @@ showAccountDebug a = printf "%-25s %4s %4s %s" (aname a) (showMixedAmount $ aebalance a) (showMixedAmount $ aibalance a) - (if aboring a then "b" else " ") + (if aboring a then "b" else " " :: String) tests_Hledger_Data_Account = TestList [ diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index db18b3d18..35a6ead8c 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -146,16 +146,18 @@ divideAmount a@Amount{quantity=q} d = a{quantity=q/d} isNegativeAmount :: Amount -> Bool isNegativeAmount Amount{quantity=q} = q < 0 +digits = "123456789" :: String + -- | Does this amount appear to be zero when displayed with its given precision ? isZeroAmount :: Amount -> Bool isZeroAmount a -- a==missingamt = False - | otherwise = (null . filter (`elem` "123456789") . showAmountWithoutPriceOrCommodity) a + | otherwise = (null . filter (`elem` digits) . showAmountWithoutPriceOrCommodity) a -- | Is this amount "really" zero, regardless of the display precision ? -- Since we are using floating point, for now just test to some high precision. isReallyZeroAmount :: Amount -> Bool isReallyZeroAmount a -- a==missingamt = False - | otherwise = (null . filter (`elem` "123456789") . printf ("%."++show zeroprecision++"f") . quantity) a + | otherwise = (null . filter (`elem` digits) . printf ("%."++show zeroprecision++"f") . quantity) a where zeroprecision = 8 -- | Get the string representation of an amount, based on its commodity's @@ -200,10 +202,10 @@ showAmount a@(Amount (Commodity {symbol=sym,side=side,spaced=spaced}) _ pri) = R -> printf "%s%s%s%s" quantity' space sym' price where quantity = showamountquantity a - displayingzero = null $ filter (`elem` "123456789") $ quantity + displayingzero = null $ filter (`elem` digits) $ quantity (quantity',sym') | displayingzero = ("0","") | otherwise = (quantity,quoteCommoditySymbolIfNeeded sym) - space = if (not (null sym') && spaced) then " " else "" + space = if (not (null sym') && spaced) then " " else "" :: String price = maybe "" showPrice pri -- | Get the string representation of the number part of of an amount, diff --git a/hledger-lib/Hledger/Data/Commodity.hs b/hledger-lib/Hledger/Data/Commodity.hs index 74fe7bcae..a99f433bb 100644 --- a/hledger-lib/Hledger/Data/Commodity.hs +++ b/hledger-lib/Hledger/Data/Commodity.hs @@ -18,7 +18,7 @@ import Hledger.Data.Types import Hledger.Utils -nonsimplecommoditychars = "0123456789-.@;\n \"" +nonsimplecommoditychars = "0123456789-.@;\n \"" :: String quoteCommoditySymbolIfNeeded s | any (`elem` nonsimplecommoditychars) s = "\"" ++ s ++ "\"" | otherwise = s diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 08810a7a3..e307a81c4 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE NoMonoLocalBinds #-} {-| Date parsing and utilities for hledger. diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 9dd705a49..2ece21a3d 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -340,7 +340,7 @@ nonzerobalanceerror t = printf "could not balance this transaction (%s%s%s)" rms | otherwise = "real postings are off by " ++ showMixedAmount (costOfMixedAmount rsum) bvmsg | isReallyZeroMixedAmountCost bvsum = "" | otherwise = "balanced virtual postings are off by " ++ showMixedAmount (costOfMixedAmount bvsum) - sep = if not (null rmsg) && not (null bvmsg) then "; " else "" + sep = if not (null rmsg) && not (null bvmsg) then "; " else "" :: String transactionActualDate :: Transaction -> Day transactionActualDate = tdate diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index 346ccf6c2..05ac8b3eb 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE RecordWildCards, NoMonoLocalBinds #-} {-| A reader for hledger's journal file format diff --git a/hledger-lib/Hledger/Utils.hs b/hledger-lib/Hledger/Utils.hs index 6f76041c4..36990df9f 100644 --- a/hledger-lib/Hledger/Utils.hs +++ b/hledger-lib/Hledger/Utils.hs @@ -55,7 +55,7 @@ lowercase = map toLower uppercase = map toUpper strip = lstrip . rstrip -lstrip = dropWhile (`elem` " \t") +lstrip = dropWhile (`elem` " \t") :: String -> String rstrip = reverse . lstrip . reverse elideLeft width s = diff --git a/hledger/Hledger/Cli/Add.hs b/hledger/Hledger/Cli/Add.hs index 6f728db91..998265b9a 100644 --- a/hledger/Hledger/Cli/Add.hs +++ b/hledger/Hledger/Cli/Add.hs @@ -117,7 +117,7 @@ getPostings st enteredps = do | otherwise = Nothing where Just ps = historicalps defaultaccount = maybe Nothing (Just . showacctname) bestmatch - ordot | null enteredps || length enteredrealps == 1 = "" + ordot | null enteredps || length enteredrealps == 1 = "" :: String | otherwise = ", or . to record" account <- runInteraction j $ askFor (printf "account %d%s" n ordot) defaultaccount (Just accept) if account=="." diff --git a/hledger/Hledger/Cli/Stats.hs b/hledger/Hledger/Cli/Stats.hs index 852650b99..7142a519f 100644 --- a/hledger/Hledger/Cli/Stats.hs +++ b/hledger/Hledger/Cli/Stats.hs @@ -41,7 +41,7 @@ showLedgerStats l today span = w1 = maximum $ map (length . fst) stats -- w2 = maximum $ map (length . show . snd) stats stats = [ - ("Main journal file", path) -- ++ " (from " ++ source ++ ")") + ("Main journal file" :: String, path) -- ++ " (from " ++ source ++ ")") ,("Included journal files", unlines $ reverse $ -- cf journalAddFile drop 1 $ journalFilePaths j) ,("Transactions span", printf "%s to %s (%d days)" (start span) (end span) days) @@ -69,7 +69,7 @@ showLedgerStats l today span = showelapsed Nothing = "" showelapsed (Just days) = printf " (%d %s)" days' direction where days' = abs days - direction | days >= 0 = "days ago" + direction | days >= 0 = "days ago" :: String | otherwise = "days from now" tnum = length ts start (DateSpan (Just d) _) = show d diff --git a/hledger/Hledger/Cli/Version.hs b/hledger/Hledger/Cli/Version.hs index 0fa4a6415..bec7a2757 100644 --- a/hledger/Hledger/Cli/Version.hs +++ b/hledger/Hledger/Cli/Version.hs @@ -55,7 +55,7 @@ binaryfilename progname = prettify $ splitAtElement '.' buildversion | patches/="0" = '+' : patches | otherwise = "" (os',suffix) - | os == "darwin" = ("mac","") + | os == "darwin" = ("mac","" :: String) | os == "mingw32" = ("windows",".exe") | otherwise = (os,"") prettify (major:minor:bugfix:[]) = prettify [major,minor,bugfix,"0"]