Strip prices after valuing postings in PostingsReport.
Use renderRow interface for Register report.
For reg -f examples/10000x10000x10.journal, this results in:
- Heap allocations decreasing by 55%, from 68.6GB to 31.2GB
- Resident memory decreasing by 75%, from 254GB to 65GB
- Total (profiled) time decreasing by 55%, from 37s to 20s
former being a simple wrapper around the latter.
This removes the need for the showNormalised option, as showMixedAmountB
will always showNormalised and showAmountsB will never do so.
We also strip prices from MixedAmount before displaying if not displaying prices.
Previously we relied on MixedAmount being a Num, which allows +, -,
sum, negate, fromInteger etc. to be used with MixedAmounts. While
convenient, this Num instance is not (and can't be) fully implemented
or law abiding, so it's possible to misuse it, potentially leading to
bugs.
Now, MixedAmount is a lawful Monoid (and a Semigroup), so you can
combine (add) MixedAmounts with <> or mconcat and represent zero with
mempty.
However, we recommend using the following more abstract API, which
will insulate you from future implementation changes:
maPlus (instead of +)
maMinus (instead of -)
maNegate (instead of negate)
maSum (instead of sum/sumStrict)
nullmixedamt (instead of 0)
And when constructing MixedAmounts, avoid the Mixed constructor,
instead use:
mixed :: [Amount] -> MixedAmount
mixedAmount :: Amount -> MixedAmount
maAddAmount :: MixedAmount -> Amount -> MixedAmount
maAddAmounts :: MixedAmount -> [Amount] -> MixedAmount
For now the Num instance remains, as a convenience for scripters and
for backward compatibility, but for production code you should
probably consider it deprecated.
Exceptions are for dealing with the pamount field, which is really just
dealing with an unnormalised list of amounts.
This creates an API for dealing with MixedAmount, so we never have to
access the internals outside of Hledger.Data.Amount.
Also remove a comment, since it looks like #1207 has been resolved.
supplant the old interface, which relied on the Num typeclass.
MixedAmount did not have a very good Num instance. The only functions
which were defined were fromInteger, (+), and negate. Furthermore, it
was not law-abiding, as 0 + a /= a in general. Replacements for used
functions are:
0 -> nullmixedamt / mempty
(+) -> maPlus / (<>)
(-) -> maMinus
negate -> maNegate
sum -> maSum
sumStrict -> maSum
Also creates some new constructors for MixedAmount:
mixedAmount :: Amount -> MixedAmount
maAddAmount :: MixedAmount -> Amount -> MixedAmount
maAddAmounts :: MixedAmount -> [Amount] -> MixedAmount
Add Semigroup and Monoid instances for MixedAmount.
Ideally we would remove the Num instance entirely.
The only change needed have nullmixedamt/mempty substitute for
0 without problems was to not squash prices in
mixedAmount(Looks|Is)Zero. This is correct behaviour in any case.