lib: Debug: simplify pprint, export ppShow as pshow (api change)

This commit is contained in:
Simon Michael 2018-07-16 12:47:37 +01:00
parent f62e308c9c
commit 9d2e80aa2c
2 changed files with 11 additions and 7 deletions

View File

@ -69,11 +69,11 @@ type MultiBalanceReportRow = (AccountName, AccountName, Int, [MixedAmount], M
type MultiBalanceReportTotals = ([MixedAmount], MixedAmount, MixedAmount) -- (Totals list, sum of totals, average of totals)
instance Show MultiBalanceReport where
-- use ppShow to break long lists onto multiple lines
-- we add some bogus extra shows here to help ppShow parse the output
-- use pshow (pretty-show's ppShow) to break long lists onto multiple lines
-- we add some bogus extra shows here to help it parse the output
-- and wrap tuples and lists properly
show (MultiBalanceReport (spans, items, totals)) =
"MultiBalanceReport (ignore extra quotes):\n" ++ ppShow (show spans, map show items, totals)
"MultiBalanceReport (ignore extra quotes):\n" ++ pshow (show spans, map show items, totals)
-- type alias just to remind us which AccountNames might be depth-clipped, below.
type ClippedAccountName = AccountName

View File

@ -8,9 +8,8 @@
-- http://hackage.haskell.org/packages/archive/traced/2009.7.20/doc/html/Debug-Traced.html
module Hledger.Utils.Debug (
module Hledger.Utils.Debug
module Hledger.Utils.Debug
,module Debug.Trace
,ppShow
)
where
@ -26,10 +25,15 @@ import System.Exit
import System.IO.Unsafe (unsafePerformIO)
import Text.Megaparsec
import Text.Printf
import Text.Show.Pretty (ppShow)
import Text.Show.Pretty (ppShow, pPrint)
-- | Easier alias for pretty-show's pPrint.
pprint :: Show a => a -> IO ()
pprint = putStrLn . ppShow
pprint = pPrint
-- | Easier alias for pretty-show's ppShow.
pshow :: Show a => a -> String
pshow = ppShow
-- | Trace (print to stderr) a showable value using a custom show function.
traceWith :: (a -> String) -> a -> a